Passed
Pull Request — master (#49)
by Mage
02:28
created

AddRemainingProduct::execute()   B

Complexity

Conditions 9
Paths 60

Size

Total Lines 37
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 9
eloc 26
c 2
b 0
f 0
nc 60
nop 1
dl 0
loc 37
rs 8.0555
1
<?php
2
3
/**
4
 * MagePrince
5
 * Copyright (C) 2020 Mageprince <[email protected]>
6
 *
7
 * @package Mageprince_BuyNow
8
 * @copyright Copyright (c) 2020 Mageprince (http://www.mageprince.com/)
9
 * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License,version 3 (GPL-3.0)
10
 * @author MagePrince <[email protected]>
11
 */
12
13
namespace Mageprince\BuyNow\Observer;
14
15
use Magento\Checkout\Model\Cart as CustomerCart;
0 ignored issues
show
Bug introduced by
The type Magento\Checkout\Model\Cart 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...
16
17
class AddRemainingProduct implements \Magento\Framework\Event\ObserverInterface
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Event\ObserverInterface 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...
18
{
19
20
    /**
21
     * @param \Magento\Quote\Model\QuoteFactory $quoteFactory
22
     * @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
23
     * @param CustomerCart $cart
24
     */
25
    public function __construct(
26
        \Magento\Quote\Model\QuoteFactory $quoteFactory,
0 ignored issues
show
Bug introduced by
The type Magento\Quote\Model\QuoteFactory 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...
27
        \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
0 ignored issues
show
Bug introduced by
The type Magento\Customer\Api\CustomerRepositoryInterface 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...
28
        CustomerCart $cart
29
    ) {
30
        $this->quoteFactory = $quoteFactory;
0 ignored issues
show
Bug Best Practice introduced by
The property quoteFactory does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
31
        $this->customerRepository = $customerRepository;
0 ignored issues
show
Bug Best Practice introduced by
The property customerRepository does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
32
        $this->cart = $cart;
0 ignored issues
show
Bug Best Practice introduced by
The property cart does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
33
    }
34
35
    public function execute(\Magento\Framework\Event\Observer $observer)
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Event\Observer 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...
36
    {
37
        $flage = 1;
38
        try {
39
            $order = $observer->getEvent()->getOrder();
40
            $quoteData = $this->quoteFactory->create();
41
            $quoteData->load($order->getQuoteId());
42
            if ($quoteData->hasData()) {
43
                if ($quoteData->getBuyNowId()) {
44
                    if ($quoteData->getCustomerId()) {
45
                        $customerRepoData = $this->customerRepository->getById($quoteData->getCustomerId());
46
                        $quoteDataReplace = $this->quoteFactory->create();
47
                        $quoteDataReplace->load($quoteData->getBuyNowId());
48
                        if ($quoteDataReplace->hasData()) {
49
50
                            $quoteDataReplace->assignCustomer($customerRepoData);
51
                            $quoteDataReplace->setBuyNowId(0);
52
                            $quoteDataReplace->setIsActive(1);
53
                            $quoteDataReplace->save();
54
55
                            /* Update buynow cart Value */
56
                            if ($observer->getEvent()->getUpdateData()) {
57
                                $quoteData->setBuyNowId(0);
58
                                $quoteDataReplace->setIsActive(0);
59
                                $quoteData->save();
60
                            }
61
62
                        }
63
                    }
64
                }
65
            }
66
        } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Exception\NoSuchEntityException 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...
67
            $flage = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $flage is dead and can be removed.
Loading history...
68
        } catch (\Magento\Framework\Exception\LocalizedException $e) {
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Exception\LocalizedException 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...
69
            $flage = 0;
70
        } catch (\Exception $e) {
71
            $flage = 0;
72
        }
73
    }
74
}
75