1 | <?php |
||||||
2 | |||||||
3 | /** |
||||||
4 | * MagePrince |
||||||
5 | * |
||||||
6 | * NOTICE OF LICENSE |
||||||
7 | * |
||||||
8 | * This source file is subject to the mageprince.com license that is |
||||||
9 | * available through the world-wide-web at this URL: |
||||||
10 | * https://mageprince.com/end-user-license-agreement |
||||||
11 | * |
||||||
12 | * DISCLAIMER |
||||||
13 | * |
||||||
14 | * Do not edit or add to this file if you wish to upgrade this extension to newer |
||||||
15 | * version in the future. |
||||||
16 | * |
||||||
17 | * @category MagePrince |
||||||
18 | * @package Mageprince_BuyNow |
||||||
19 | * @copyright Copyright (c) MagePrince (https://mageprince.com/) |
||||||
20 | * @license https://mageprince.com/end-user-license-agreement |
||||||
21 | */ |
||||||
22 | |||||||
23 | namespace Mageprince\BuyNow\Controller\Cart; |
||||||
24 | |||||||
25 | use Magento\Framework\Filter\LocalizedToNormalized; |
||||||
0 ignored issues
–
show
|
|||||||
26 | use Mageprince\BuyNow\ViewModel\BuyNow as BuyNowViewModel; |
||||||
27 | |||||||
28 | class Add extends \Magento\Checkout\Controller\Cart\Add |
||||||
0 ignored issues
–
show
The type
Magento\Checkout\Controller\Cart\Add 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
29 | { |
||||||
30 | /** |
||||||
31 | * Add product to shopping cart action |
||||||
32 | * |
||||||
33 | * @return \Magento\Framework\Controller\Result\Redirect |
||||||
0 ignored issues
–
show
The type
Magento\Framework\Controller\Result\Redirect 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
34 | * @SuppressWarnings(PHPMD.CyclomaticComplexity) |
||||||
35 | */ |
||||||
36 | public function execute() |
||||||
37 | { |
||||||
38 | if (!$this->_formKeyValidator->validate($this->getRequest())) { |
||||||
39 | $this->messageManager->addErrorMessage( |
||||||
40 | __('Your session has expired') |
||||||
0 ignored issues
–
show
The function
__ 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
![]() |
|||||||
41 | ); |
||||||
42 | return $this->resultRedirectFactory->create()->setPath('*/*/'); |
||||||
43 | } |
||||||
44 | |||||||
45 | $params = $this->getRequest()->getParams(); |
||||||
46 | |||||||
47 | try { |
||||||
48 | if (isset($params['qty'])) { |
||||||
49 | $filter = new LocalizedToNormalized( |
||||||
50 | ['locale' => $this->_objectManager->get( |
||||||
51 | \Magento\Framework\Locale\ResolverInterface::class |
||||||
0 ignored issues
–
show
The type
Magento\Framework\Locale\ResolverInterface 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
52 | )->getLocale()] |
||||||
53 | ); |
||||||
54 | $params['qty'] = $filter->filter($params['qty']); |
||||||
55 | } |
||||||
56 | |||||||
57 | $product = $this->_initProduct(); |
||||||
58 | $related = $this->getRequest()->getParam('related_product'); |
||||||
59 | |||||||
60 | /** |
||||||
61 | * Check product availability |
||||||
62 | */ |
||||||
63 | if (!$product) { |
||||||
64 | return $this->goBack(); |
||||||
65 | } |
||||||
66 | |||||||
67 | $buyNowHelper = $this->_objectManager->create(BuyNowViewModel::class); |
||||||
68 | $cartProducts = $buyNowHelper->keepCartProducts(); |
||||||
69 | if (!$cartProducts) { |
||||||
70 | $this->cart->truncate(); //remove all products from cart |
||||||
71 | } |
||||||
72 | |||||||
73 | $this->cart->addProduct($product, $params); |
||||||
74 | if (!empty($related)) { |
||||||
75 | $this->cart->addProductsByIds(explode(',', $related)); |
||||||
76 | } |
||||||
77 | $this->cart->save(); |
||||||
78 | |||||||
79 | /** |
||||||
80 | * @todo remove wishlist observer \Magento\Wishlist\Observer\AddToCart |
||||||
81 | */ |
||||||
82 | $this->_eventManager->dispatch( |
||||||
83 | 'checkout_cart_add_product_complete', |
||||||
84 | ['product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse()] |
||||||
85 | ); |
||||||
86 | |||||||
87 | if (!$this->_checkoutSession->getNoCartRedirect(true)) { |
||||||
88 | $baseUrl = $this->_url->getBaseUrl(); |
||||||
89 | return $this->goBack($baseUrl . 'checkout/', $product); |
||||||
90 | } |
||||||
91 | } catch (\Magento\Framework\Exception\LocalizedException $e) { |
||||||
0 ignored issues
–
show
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
92 | if ($this->_checkoutSession->getUseNotice(true)) { |
||||||
93 | $this->messageManager->addNoticeMessage( |
||||||
94 | $this->_objectManager->get(\Magento\Framework\Escaper::class)->escapeHtml($e->getMessage()) |
||||||
0 ignored issues
–
show
The type
Magento\Framework\Escaper 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
95 | ); |
||||||
96 | } else { |
||||||
97 | $messages = array_unique(explode("\n", $e->getMessage())); |
||||||
98 | foreach ($messages as $message) { |
||||||
99 | $this->messageManager->addErrorMessage( |
||||||
100 | $this->_objectManager->get(\Magento\Framework\Escaper::class)->escapeHtml($message) |
||||||
101 | ); |
||||||
102 | } |
||||||
103 | } |
||||||
104 | $url = $this->_checkoutSession->getRedirectUrl(true); |
||||||
105 | if (!$url) { |
||||||
106 | $cartUrl = $this->_objectManager->get(\Magento\Checkout\Helper\Cart::class)->getCartUrl(); |
||||||
0 ignored issues
–
show
The type
Magento\Checkout\Helper\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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
107 | $url = $this->_redirect->getRedirectUrl($cartUrl); |
||||||
108 | } |
||||||
109 | return $this->goBack($url); |
||||||
110 | } catch (\Exception $e) { |
||||||
111 | $this->messageManager->addExceptionMessage( |
||||||
112 | $e, |
||||||
113 | __('We can\'t add this item to your shopping cart right now.') |
||||||
114 | ); |
||||||
115 | $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); |
||||||
0 ignored issues
–
show
The type
Psr\Log\LoggerInterface 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
116 | return $this->goBack(); |
||||||
117 | } |
||||||
118 | } |
||||||
119 | } |
||||||
120 |
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