|
@@ -36,14 +36,14 @@ discard block |
|
|
block discarded – undo |
|
36
|
36
|
* @param string $stocktype Unique code of the stock type to deliver the products from |
|
37
|
37
|
* @throws \Aimeos\Controller\Frontend\Basket\Exception If the product isn't available |
|
38
|
38
|
*/ |
|
39
|
|
- public function addProduct( $prodid, $quantity = 1, $stocktype = 'default', array $variantAttributeIds = [], |
|
40
|
|
- array $configAttributeIds = [], array $hiddenAttributeIds = [], array $customAttributeValues = [] ) |
|
|
39
|
+ public function addProduct($prodid, $quantity = 1, $stocktype = 'default', array $variantAttributeIds = [], |
|
|
40
|
+ array $configAttributeIds = [], array $hiddenAttributeIds = [], array $customAttributeValues = []) |
|
41
|
41
|
{ |
|
42
|
42
|
$context = $this->getContext(); |
|
43
|
|
- $productManager = \Aimeos\MShop\Factory::createManager( $context, 'product' ); |
|
44
|
|
- $productItem = $productManager->getItem( $prodid, [], true ); |
|
|
43
|
+ $productManager = \Aimeos\MShop\Factory::createManager($context, 'product'); |
|
|
44
|
+ $productItem = $productManager->getItem($prodid, [], true); |
|
45
|
45
|
|
|
46
|
|
- if( $productManager->getItem( $prodid, [], true )->getType() !== 'select' ) |
|
|
46
|
+ if ($productManager->getItem($prodid, [], true)->getType() !== 'select') |
|
47
|
47
|
{ |
|
48
|
48
|
return $this->getController()->addProduct( |
|
49
|
49
|
$prodid, $quantity, $stocktype, $variantAttributeIds, |
|
@@ -51,30 +51,30 @@ discard block |
|
|
block discarded – undo |
|
51
|
51
|
); |
|
52
|
52
|
} |
|
53
|
53
|
|
|
54
|
|
- $productItem = $productManager->getItem( $prodid, ['attribute', 'media', 'supplier', 'price', 'product', 'text'], true ); |
|
55
|
|
- $prices = $productItem->getRefItems( 'price', 'default', 'default' ); |
|
56
|
|
- $hidden = $productItem->getRefItems( 'attribute', null, 'hidden' ); |
|
|
54
|
+ $productItem = $productManager->getItem($prodid, ['attribute', 'media', 'supplier', 'price', 'product', 'text'], true); |
|
|
55
|
+ $prices = $productItem->getRefItems('price', 'default', 'default'); |
|
|
56
|
+ $hidden = $productItem->getRefItems('attribute', null, 'hidden'); |
|
57
|
57
|
|
|
58
|
|
- $orderBaseProductItem = \Aimeos\MShop\Factory::createManager( $context, 'order/base/product' )->createItem(); |
|
59
|
|
- $orderBaseProductItem->copyFrom( $productItem )->setQuantity( $quantity )->setStockType( $stocktype ); |
|
|
58
|
+ $orderBaseProductItem = \Aimeos\MShop\Factory::createManager($context, 'order/base/product')->createItem(); |
|
|
59
|
+ $orderBaseProductItem->copyFrom($productItem)->setQuantity($quantity)->setStockType($stocktype); |
|
60
|
60
|
|
|
61
|
|
- $attr = $this->getVariantDetails( $orderBaseProductItem, $productItem, $prices, $variantAttributeIds ); |
|
62
|
|
- $hidden += $productItem->getRefItems( 'attribute', null, 'hidden' ); |
|
|
61
|
+ $attr = $this->getVariantDetails($orderBaseProductItem, $productItem, $prices, $variantAttributeIds); |
|
|
62
|
+ $hidden += $productItem->getRefItems('attribute', null, 'hidden'); |
|
63
|
63
|
|
|
64
|
64
|
$attributeMap = [ |
|
65
|
|
- 'custom' => array_keys( $customAttributeValues ), |
|
66
|
|
- 'config' => array_keys( $configAttributeIds ), |
|
|
65
|
+ 'custom' => array_keys($customAttributeValues), |
|
|
66
|
+ 'config' => array_keys($configAttributeIds), |
|
67
|
67
|
]; |
|
68
|
|
- $this->checkListRef( array( $prodid, $productItem->getId() ), 'attribute', $attributeMap ); |
|
|
68
|
+ $this->checkListRef(array($prodid, $productItem->getId()), 'attribute', $attributeMap); |
|
69
|
69
|
|
|
70
|
|
- $custAttr = $this->getOrderProductAttributes( 'custom', array_keys( $customAttributeValues ), $customAttributeValues ); |
|
71
|
|
- $confAttr = $this->getOrderProductAttributes( 'config', array_keys( $configAttributeIds ), [], $configAttributeIds ); |
|
72
|
|
- $attr = array_merge( $attr, $custAttr, $confAttr, $this->getOrderProductAttributes( 'hidden', array_keys( $hidden ) ) ); |
|
|
70
|
+ $custAttr = $this->getOrderProductAttributes('custom', array_keys($customAttributeValues), $customAttributeValues); |
|
|
71
|
+ $confAttr = $this->getOrderProductAttributes('config', array_keys($configAttributeIds), [], $configAttributeIds); |
|
|
72
|
+ $attr = array_merge($attr, $custAttr, $confAttr, $this->getOrderProductAttributes('hidden', array_keys($hidden))); |
|
73
|
73
|
|
|
74
|
|
- $orderBaseProductItem->setAttributes( $attr ); |
|
75
|
|
- $orderBaseProductItem->setPrice( $this->calcPrice( $orderBaseProductItem, $prices, $quantity ) ); |
|
|
74
|
+ $orderBaseProductItem->setAttributes($attr); |
|
|
75
|
+ $orderBaseProductItem->setPrice($this->calcPrice($orderBaseProductItem, $prices, $quantity)); |
|
76
|
76
|
|
|
77
|
|
- $this->getController()->get()->addProduct( $orderBaseProductItem ); |
|
|
77
|
+ $this->getController()->get()->addProduct($orderBaseProductItem); |
|
78
|
78
|
$this->getController()->save(); |
|
79
|
79
|
} |
|
80
|
80
|
|
|
@@ -89,12 +89,12 @@ discard block |
|
|
block discarded – undo |
|
89
|
89
|
* @return \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface[] List of order product attributes |
|
90
|
90
|
* @throws \Aimeos\Controller\Frontend\Basket\Exception If no product variant is found |
|
91
|
91
|
*/ |
|
92
|
|
- protected function getVariantDetails( \Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem, |
|
93
|
|
- \Aimeos\MShop\Product\Item\Iface &$productItem, array &$prices, array $variantAttributeIds ) |
|
|
92
|
+ protected function getVariantDetails(\Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem, |
|
|
93
|
+ \Aimeos\MShop\Product\Item\Iface &$productItem, array &$prices, array $variantAttributeIds) |
|
94
|
94
|
{ |
|
95
|
95
|
$attr = []; |
|
96
|
96
|
$context = $this->getContext(); |
|
97
|
|
- $productItems = $this->getProductVariants( $productItem, $variantAttributeIds ); |
|
|
97
|
+ $productItems = $this->getProductVariants($productItem, $variantAttributeIds); |
|
98
|
98
|
|
|
99
|
99
|
/** controller/frontend/basket/require-variant |
|
100
|
100
|
* A variant of a selection product must be chosen |
|
@@ -115,47 +115,47 @@ discard block |
|
|
block discarded – undo |
|
115
|
115
|
* @category Developer |
|
116
|
116
|
* @category User |
|
117
|
117
|
*/ |
|
118
|
|
- $requireVariant = $context->getConfig()->get( 'controller/frontend/basket/require-variant', true ); |
|
|
118
|
+ $requireVariant = $context->getConfig()->get('controller/frontend/basket/require-variant', true); |
|
119
|
119
|
|
|
120
|
120
|
|
|
121
|
|
- if( count( $productItems ) > 1 ) |
|
|
121
|
+ if (count($productItems) > 1) |
|
122
|
122
|
{ |
|
123
|
|
- $msg = $context->getI18n()->dt( 'controller/frontend', 'No unique article found for selected attributes and product ID "%1$s"' ); |
|
124
|
|
- throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( $msg, $productItem->getId() ) ); |
|
|
123
|
+ $msg = $context->getI18n()->dt('controller/frontend', 'No unique article found for selected attributes and product ID "%1$s"'); |
|
|
124
|
+ throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf($msg, $productItem->getId())); |
|
125
|
125
|
} |
|
126
|
|
- else if( ( $result = reset( $productItems ) ) !== false ) // count == 1 |
|
|
126
|
+ else if (($result = reset($productItems)) !== false) // count == 1 |
|
127
|
127
|
{ |
|
128
|
128
|
$productItem = $result; |
|
129
|
|
- $orderBaseProductItem->setProductCode( $productItem->getCode() ); |
|
|
129
|
+ $orderBaseProductItem->setProductCode($productItem->getCode()); |
|
130
|
130
|
|
|
131
|
|
- $subprices = $productItem->getRefItems( 'price', 'default', 'default' ); |
|
|
131
|
+ $subprices = $productItem->getRefItems('price', 'default', 'default'); |
|
132
|
132
|
|
|
133
|
|
- if( !empty( $subprices ) ) { |
|
|
133
|
+ if (!empty($subprices)) { |
|
134
|
134
|
$prices = $subprices; |
|
135
|
135
|
} |
|
136
|
136
|
|
|
137
|
|
- $submedia = $productItem->getRefItems( 'media', 'default', 'default' ); |
|
|
137
|
+ $submedia = $productItem->getRefItems('media', 'default', 'default'); |
|
138
|
138
|
|
|
139
|
|
- if( ( $mediaItem = reset( $submedia ) ) !== false ) { |
|
140
|
|
- $orderBaseProductItem->setMediaUrl( $mediaItem->getPreview() ); |
|
|
139
|
+ if (($mediaItem = reset($submedia)) !== false) { |
|
|
140
|
+ $orderBaseProductItem->setMediaUrl($mediaItem->getPreview()); |
|
141
|
141
|
} |
|
142
|
142
|
|
|
143
|
|
- $orderProductAttrManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order/base/product/attribute' ); |
|
144
|
|
- $variantAttributes = $productItem->getRefItems( 'attribute', null, 'variant' ); |
|
|
143
|
+ $orderProductAttrManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'order/base/product/attribute'); |
|
|
144
|
+ $variantAttributes = $productItem->getRefItems('attribute', null, 'variant'); |
|
145
|
145
|
|
|
146
|
|
- foreach( $this->getAttributes( array_keys( $variantAttributes ), array( 'text' ) ) as $attrItem ) |
|
|
146
|
+ foreach ($this->getAttributes(array_keys($variantAttributes), array('text')) as $attrItem) |
|
147
|
147
|
{ |
|
148
|
148
|
$orderAttributeItem = $orderProductAttrManager->createItem(); |
|
149
|
|
- $orderAttributeItem->copyFrom( $attrItem ); |
|
150
|
|
- $orderAttributeItem->setType( 'variant' ); |
|
|
149
|
+ $orderAttributeItem->copyFrom($attrItem); |
|
|
150
|
+ $orderAttributeItem->setType('variant'); |
|
151
|
151
|
|
|
152
|
152
|
$attr[] = $orderAttributeItem; |
|
153
|
153
|
} |
|
154
|
154
|
} |
|
155
|
|
- else if( $requireVariant != false ) // count == 0 |
|
|
155
|
+ else if ($requireVariant != false) // count == 0 |
|
156
|
156
|
{ |
|
157
|
|
- $msg = $context->getI18n()->dt( 'controller/frontend', 'No article found for selected attributes and product ID "%1$s"' ); |
|
158
|
|
- throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( $msg, $productItem->getId() ) ); |
|
|
157
|
+ $msg = $context->getI18n()->dt('controller/frontend', 'No article found for selected attributes and product ID "%1$s"'); |
|
|
158
|
+ throw new \Aimeos\Controller\Frontend\Basket\Exception(sprintf($msg, $productItem->getId())); |
|
159
|
159
|
} |
|
160
|
160
|
|
|
161
|
161
|
return $attr; |