Passed
Push — master ( 81a345...8ff05f )
by Matthijs
01:44
created

OrderRepository::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 12
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A OrderRepository::getOrderPaymentMethodModel() 0 3 1
A OrderRepository::getOrderSendingMethodModel() 0 3 1
1
<?php
2
namespace Hideyo\Ecommerce\Framework\Services\Order\Entity;
3
 
4
use Hideyo\Ecommerce\Framework\Services\Order\Entity\Order;
5
use Hideyo\Ecommerce\Framework\Services\Order\Entity\OrderProduct;
6
use Hideyo\Ecommerce\Framework\Services\Order\Entity\OrderAddress;
7
use Hideyo\Ecommerce\Framework\Services\Order\Entity\OrderSendingMethod;
8
use Hideyo\Ecommerce\Framework\Services\Order\Entity\OrderPaymentMethod;
9
use DB;
0 ignored issues
show
Bug introduced by
The type DB was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Carbon\Carbon;
0 ignored issues
show
Bug introduced by
The type Carbon\Carbon was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Hideyo\Ecommerce\Framework\Services\BaseRepository;
12
 
13
class OrderRepository extends BaseRepository 
14
{
15
    protected $model;
16
17
    public function __construct(
18
        Order $model,
19
        OrderProduct $modelOrderProduct,
20
        OrderAddress $modelOrderAddress,
21
        OrderSendingMethod $modelOrderSendingMethod,
22
        OrderPaymentMethod $modelOrderPaymentMethod
23
    ) {
24
        $this->model = $model;
25
        $this->modelOrderProduct = $modelOrderProduct;
0 ignored issues
show
Bug Best Practice introduced by
The property modelOrderProduct does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
26
        $this->modelOrderAddress = $modelOrderAddress;
0 ignored issues
show
Bug Best Practice introduced by
The property modelOrderAddress does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
27
        $this->modelOrderSendingMethod = $modelOrderSendingMethod;
0 ignored issues
show
Bug Best Practice introduced by
The property modelOrderSendingMethod does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
28
        $this->modelOrderPaymentMethod = $modelOrderPaymentMethod;
0 ignored issues
show
Bug Best Practice introduced by
The property modelOrderPaymentMethod does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
29
    }
30
  
31
    public function getProductModel()
32
    {
33
        return $this->modelOrderProduct;
34
    }
35
36
    public function getAddressModel()
37
    {
38
        return $this->modelOrderAddress;
39
    }
40
41
    public function getOrderSendingMethodModel()
42
    {
43
        return $this->modelOrderSendingMethod;
44
    }
45
46
    public function getOrderPaymentMethodModel()
47
    {
48
        return $this->modelOrderPaymentMethod;
49
    }
50
51
    public function selectAllByShopIdAndStatusId($orderStatusId, $startDate = false, $endDate = false, $shopId = false)
0 ignored issues
show
Unused Code introduced by
The parameter $shopId is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

51
    public function selectAllByShopIdAndStatusId($orderStatusId, $startDate = false, $endDate = false, /** @scrutinizer ignore-unused */ $shopId = false)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
52
    {
53
        $query = $this->model
54
        ->where('shop_id', '=', auth('hideyobackend')->user()->selected_shop_id)
0 ignored issues
show
Bug introduced by
The function auth was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
        ->where('shop_id', '=', /** @scrutinizer ignore-call */ auth('hideyobackend')->user()->selected_shop_id)
Loading history...
55
        ->where('order_status_id', '=', $orderStatusId);
56
57
        if ($startDate) {
58
            $dt = Carbon::createFromFormat('d/m/Y', $startDate);
59
            $query->where('created_at', '>=', $dt->toDateString('Y-m-d'));
60
        }
61
62
        if ($endDate) {
63
            $dt = Carbon::createFromFormat('d/m/Y', $endDate);
64
            $query->where('created_at', '<=', $dt->toDateString('Y-m-d'));
65
        }
66
67
        $query->orderBy('created_at', 'ASC');
68
        return $query->get();
69
    }
70
71
    public function selectAllByAllProductsAndProductCategoryId($productCategoryId)
72
    {
73
        return $this->model->select('extra_field.*')->leftJoin('product_category_related_extra_field', 'extra_field.id', '=', 'product_category_related_extra_field.extra_field_id')->where('all_products', '=', 1)->orWhere('product_category_related_extra_field.product_category_id', '=', $productCategoryId)->get();
74
    }
75
76
    public function orderProductsByClientId($clientId, $shopId)
77
    {
78
        return $this->modelOrderProduct->with(array('product'))->whereHas('Order', function ($query) use ($clientId, $shopId) {
79
            $query->where('client_id', '=', $clientId)->where('shop_id', '=', $shopId);
80
        });
81
    }
82
83
    public function selectAllByCompany()
84
    {
85
        return $this->model->leftJoin('shop', 'order.shop_id', '=', 'shop.id')->get();
86
    }
87
88
    public function productsByOrderIds(array $orderIds) 
89
    {
90
        $result = DB::table('order_product')
91
        ->select(DB::raw('DISTINCT(CONCAT_WS(\' - \',order_product.title, IFNULL(order_product.product_attribute_title, \'\'))) as title, order_product.product_attribute_title, order_product.reference_code, order_product.price_with_tax, order_product.price_without_tax,  SUM(order_product.amount) as total_amount'))
92
        ->whereIn('order_product.order_id', $orderIds)
93
        ->whereNotNull('order_product.product_attribute_title')
94
        ->groupBy('order_product.title', 'order_product.product_attribute_title')
95
        ->get();
96
97
98
        $result2 = DB::table('order_product')
99
        ->select(DB::raw('DISTINCT(order_product.title) as title, order_product.product_attribute_title, order_product.reference_code, order_product.price_with_tax, order_product.price_without_tax,  SUM(order_product.amount) as total_amount'))
100
        ->whereIn('order_product.order_id', $orderIds)
101
        ->whereNull('order_product.product_attribute_title')
102
        ->groupBy('order_product.title', 'order_product.product_attribute_title')
103
        ->get();
104
105
        $result = array_merge($result, $result2);
106
        return $result;
107
    }
108
}