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; |
|
|
|
|
16
|
|
|
use Magento\Framework\Event\Observer; |
|
|
|
|
17
|
|
|
use Magento\Framework\Event\ObserverInterface; |
|
|
|
|
18
|
|
|
|
19
|
|
|
class AddRemainingProduct implements ObserverInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var \Magento\Quote\Model\QuoteFactory |
|
|
|
|
23
|
|
|
*/ |
24
|
|
|
protected $quoteFactory; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var \Magento\Sales\Api\OrderRepositoryInterface |
|
|
|
|
28
|
|
|
*/ |
29
|
|
|
protected $orderRepository; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var \Magento\Customer\Api\CustomerRepositoryInterface |
|
|
|
|
33
|
|
|
*/ |
34
|
|
|
protected $customerRepository; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var \Mageprince\BuyNow\Helper\Data |
38
|
|
|
*/ |
39
|
|
|
protected $buyNowHelper; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var CustomerCart |
43
|
|
|
*/ |
44
|
|
|
protected $cart; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param \Magento\Quote\Model\QuoteFactory $quoteFactory |
48
|
|
|
* @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository |
49
|
|
|
* @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository |
50
|
|
|
* @param \Mageprince\BuyNow\Helper\Data $buyNowHelper |
51
|
|
|
* @param CustomerCart $cart |
52
|
|
|
*/ |
53
|
|
|
public function __construct( |
54
|
|
|
\Magento\Quote\Model\QuoteFactory $quoteFactory, |
55
|
|
|
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository, |
56
|
|
|
\Magento\Customer\Api\CustomerRepositoryInterface $customerRepository, |
57
|
|
|
\Mageprince\BuyNow\Helper\Data $buyNowHelper, |
58
|
|
|
CustomerCart $cart |
59
|
|
|
) { |
60
|
|
|
$this->quoteFactory = $quoteFactory; |
61
|
|
|
$this->orderRepository = $orderRepository; |
62
|
|
|
$this->customerRepository = $customerRepository; |
63
|
|
|
$this->buyNowHelper = $buyNowHelper; |
64
|
|
|
$this->cart = $cart; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function execute(Observer $observer) |
68
|
|
|
{ |
69
|
|
|
$flage = 1; |
70
|
|
|
$keepCartProduct = $this->buyNowHelper->keepCartProducts(); |
71
|
|
|
$updateBuyNowCart = $restoreCartProduct = $this->buyNowHelper->restoreCartProducts(); |
72
|
|
|
if (($keepCartProduct == 0) && ($restoreCartProduct == 1)) { |
73
|
|
|
try { |
74
|
|
|
$orderIds = $observer->getEvent()->getOrderIds(); |
75
|
|
|
foreach ($orderIds as $orderIdsKey => $orderIdsVal) { |
76
|
|
|
$orderData = $this->orderRepository->get($orderIdsVal); |
77
|
|
|
$quoteData = $this->quoteFactory->create(); |
78
|
|
|
$quoteData->load($orderData->getQuoteId()); |
79
|
|
|
if ($quoteData->hasData()) { |
80
|
|
|
if (($quoteData->getBuyNowId()) && ($quoteData->getCustomerId())) { |
81
|
|
|
$customerRepoData = $this->customerRepository->getById($quoteData->getCustomerId()); |
82
|
|
|
$quoteDataReplace = $this->quoteFactory->create(); |
83
|
|
|
$quoteDataReplace->load($quoteData->getBuyNowId()); |
84
|
|
|
if ($quoteDataReplace->hasData()) { |
85
|
|
|
$quoteDataReplace->assignCustomer($customerRepoData); |
86
|
|
|
$quoteDataReplace->setBuyNowId(0); |
87
|
|
|
$quoteDataReplace->setIsActive(1); |
88
|
|
|
$quoteDataReplace->save(); |
89
|
|
|
if ($updateBuyNowCart) { |
90
|
|
|
$quoteData->setBuyNowId(0); |
91
|
|
|
$quoteDataReplace->setIsActive(0); |
92
|
|
|
$quoteData->save(); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
break; |
98
|
|
|
} |
99
|
|
|
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) { |
|
|
|
|
100
|
|
|
$flage = 0; |
|
|
|
|
101
|
|
|
} catch (\Magento\Framework\Exception\LocalizedException $e) { |
|
|
|
|
102
|
|
|
$flage = 0; |
103
|
|
|
} catch (\Exception $e) { |
104
|
|
|
$flage = 0; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths