1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | |||
4 | namespace IntegerNet\AddToCartGraphQl\ViewModel; |
||
5 | |||
6 | use Magento\Catalog\Api\Data\ProductInterface; |
||
0 ignored issues
–
show
|
|||
7 | use Magento\ConfigurableProduct\Model\Product\Type\Configurable; |
||
0 ignored issues
–
show
The type
Magento\ConfigurableProd...oduct\Type\Configurable 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 ![]() |
|||
8 | use Magento\Framework\View\Element\Block\ArgumentInterface; |
||
9 | use Hyva\Theme\ViewModel\CurrentProduct; |
||
0 ignored issues
–
show
The type
Hyva\Theme\ViewModel\CurrentProduct 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 ![]() |
|||
10 | |||
11 | class AddToCartGraphQl implements ArgumentInterface |
||
12 | { |
||
13 | private CurrentProduct $currentProduct; |
||
0 ignored issues
–
show
|
|||
14 | |||
15 | public function __construct( |
||
16 | CurrentProduct $currentProduct) |
||
0 ignored issues
–
show
|
|||
17 | { |
||
0 ignored issues
–
show
|
|||
18 | $this->currentProduct = $currentProduct; |
||
19 | } |
||
20 | |||
21 | private function getProduct() : ProductInterface |
||
22 | { |
||
23 | return $this->currentProduct->get(); |
||
24 | } |
||
25 | |||
26 | public function isProductConfigurable(): bool |
||
27 | { |
||
28 | return $this->getProduct()->getTypeId() === Configurable::TYPE_CODE; |
||
29 | } |
||
30 | |||
31 | public function getAddToCartQuery(): string |
||
32 | { |
||
33 | if ($this->isProductConfigurable()) { |
||
34 | return $this->getAddToCartQueryProductTypeConfigurable(); |
||
35 | } |
||
36 | |||
37 | return $this->getAddToCartQueryProductTypeSimple(); |
||
38 | } |
||
39 | |||
40 | private function getAddToCartQueryProductTypeSimple(): string |
||
41 | { |
||
42 | return '{ |
||
43 | addProductsToCart( |
||
44 | cartId: "%cartId" |
||
45 | cartItems: [ |
||
46 | { |
||
47 | quantity: %qty |
||
48 | sku: "%sku" |
||
49 | } |
||
50 | ] |
||
51 | ) { |
||
52 | cart { |
||
53 | items { |
||
54 | product { |
||
55 | name |
||
56 | sku |
||
57 | } |
||
58 | quantity |
||
59 | } |
||
60 | } |
||
61 | } |
||
62 | }'; |
||
63 | } |
||
64 | |||
65 | private function getAddToCartQueryProductTypeConfigurable(): string |
||
66 | { |
||
67 | return '{ |
||
68 | addProductsToCart( |
||
69 | cartId: "%cartId" |
||
70 | cartItems: [ |
||
71 | { |
||
72 | quantity: %qty |
||
73 | sku: "%sku" |
||
74 | selected_options: [%selectedOptions] |
||
75 | } |
||
76 | ] |
||
77 | ) { |
||
78 | cart { |
||
79 | items { |
||
80 | product { |
||
81 | name |
||
82 | sku |
||
83 | } |
||
84 | quantity |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | }'; |
||
89 | } |
||
90 | } |
||
91 |
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