@@ -41,15 +41,15 @@ discard block |
||
41 | 41 | * @param string $stocktype Unique code of the stock type to deliver the products from |
42 | 42 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If the product isn't available |
43 | 43 | */ |
44 | - public function addProduct( $prodid, $quantity = 1, array $options = [], array $variantAttributeIds = [], |
|
44 | + public function addProduct($prodid, $quantity = 1, array $options = [], array $variantAttributeIds = [], |
|
45 | 45 | array $configAttributeIds = [], array $hiddenAttributeIds = [], array $customAttributeValues = [], |
46 | - $stocktype = 'default' ) |
|
46 | + $stocktype = 'default') |
|
47 | 47 | { |
48 | 48 | $context = $this->getContext(); |
49 | - $productManager = \Aimeos\MShop\Factory::createManager( $context, 'product' ); |
|
50 | - $productItem = $productManager->getItem( $prodid, [], true ); |
|
49 | + $productManager = \Aimeos\MShop\Factory::createManager($context, 'product'); |
|
50 | + $productItem = $productManager->getItem($prodid, [], true); |
|
51 | 51 | |
52 | - if( $productManager->getItem( $prodid, [], true )->getType() !== 'select' ) |
|
52 | + if ($productManager->getItem($prodid, [], true)->getType() !== 'select') |
|
53 | 53 | { |
54 | 54 | return $this->getController()->addProduct( |
55 | 55 | $prodid, $quantity, $options, $variantAttributeIds, $configAttributeIds, |
@@ -57,29 +57,29 @@ discard block |
||
57 | 57 | ); |
58 | 58 | } |
59 | 59 | |
60 | - $productItem = $productManager->getItem( $prodid, array( 'media', 'supplier', 'price', 'product', 'text' ), true ); |
|
61 | - $prices = $productItem->getRefItems( 'price', 'default', 'default' ); |
|
60 | + $productItem = $productManager->getItem($prodid, array('media', 'supplier', 'price', 'product', 'text'), true); |
|
61 | + $prices = $productItem->getRefItems('price', 'default', 'default'); |
|
62 | 62 | |
63 | - $orderBaseProductItem = \Aimeos\MShop\Factory::createManager( $context, 'order/base/product' )->createItem(); |
|
64 | - $orderBaseProductItem->copyFrom( $productItem )->setQuantity( $quantity )->setStockType( $stocktype ); |
|
63 | + $orderBaseProductItem = \Aimeos\MShop\Factory::createManager($context, 'order/base/product')->createItem(); |
|
64 | + $orderBaseProductItem->copyFrom($productItem)->setQuantity($quantity)->setStockType($stocktype); |
|
65 | 65 | |
66 | - $attr = $this->getVariantDetails( $orderBaseProductItem, $productItem, $prices, $variantAttributeIds, $options ); |
|
66 | + $attr = $this->getVariantDetails($orderBaseProductItem, $productItem, $prices, $variantAttributeIds, $options); |
|
67 | 67 | |
68 | 68 | $attributeMap = [ |
69 | - 'custom' => array_keys( $customAttributeValues ), |
|
70 | - 'config' => array_keys( $configAttributeIds ), |
|
69 | + 'custom' => array_keys($customAttributeValues), |
|
70 | + 'config' => array_keys($configAttributeIds), |
|
71 | 71 | 'hidden' => $hiddenAttributeIds, |
72 | 72 | ]; |
73 | - $this->checkListRef( array( $prodid, $productItem->getId() ), 'attribute', $attributeMap ); |
|
73 | + $this->checkListRef(array($prodid, $productItem->getId()), 'attribute', $attributeMap); |
|
74 | 74 | |
75 | - $attr = array_merge( $attr, $this->getOrderProductAttributes( 'custom', array_keys( $customAttributeValues ), $customAttributeValues ) ); |
|
76 | - $attr = array_merge( $attr, $this->getOrderProductAttributes( 'config', array_keys( $configAttributeIds ), [], $configAttributeIds ) ); |
|
77 | - $attr = array_merge( $attr, $this->getOrderProductAttributes( 'hidden', $hiddenAttributeIds ) ); |
|
75 | + $attr = array_merge($attr, $this->getOrderProductAttributes('custom', array_keys($customAttributeValues), $customAttributeValues)); |
|
76 | + $attr = array_merge($attr, $this->getOrderProductAttributes('config', array_keys($configAttributeIds), [], $configAttributeIds)); |
|
77 | + $attr = array_merge($attr, $this->getOrderProductAttributes('hidden', $hiddenAttributeIds)); |
|
78 | 78 | |
79 | - $orderBaseProductItem->setAttributes( $attr ); |
|
80 | - $orderBaseProductItem->setPrice( $this->calcPrice( $orderBaseProductItem, $prices, $quantity ) ); |
|
79 | + $orderBaseProductItem->setAttributes($attr); |
|
80 | + $orderBaseProductItem->setPrice($this->calcPrice($orderBaseProductItem, $prices, $quantity)); |
|
81 | 81 | |
82 | - $this->getController()->get()->addProduct( $orderBaseProductItem ); |
|
82 | + $this->getController()->get()->addProduct($orderBaseProductItem); |
|
83 | 83 | $this->getController()->save(); |
84 | 84 | } |
85 | 85 | |
@@ -95,50 +95,50 @@ discard block |
||
95 | 95 | * @return \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface[] List of order product attributes |
96 | 96 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If no product variant is found |
97 | 97 | */ |
98 | - protected function getVariantDetails( \Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem, |
|
99 | - \Aimeos\MShop\Product\Item\Iface &$productItem, array &$prices, array $variantAttributeIds, array $options ) |
|
98 | + protected function getVariantDetails(\Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem, |
|
99 | + \Aimeos\MShop\Product\Item\Iface & $productItem, array &$prices, array $variantAttributeIds, array $options) |
|
100 | 100 | { |
101 | 101 | $attr = []; |
102 | - $productItems = $this->getProductVariants( $productItem, $variantAttributeIds ); |
|
102 | + $productItems = $this->getProductVariants($productItem, $variantAttributeIds); |
|
103 | 103 | |
104 | - if( count( $productItems ) > 1 ) |
|
104 | + if (count($productItems) > 1) |
|
105 | 105 | { |
106 | - $msg = sprintf( 'No unique article found for selected attributes and product ID "%1$s"', $productItem->getId() ); |
|
107 | - throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg ); |
|
106 | + $msg = sprintf('No unique article found for selected attributes and product ID "%1$s"', $productItem->getId()); |
|
107 | + throw new \Aimeos\Controller\Frontend\Basket\Exception($msg); |
|
108 | 108 | } |
109 | - else if( ( $result = reset( $productItems ) ) !== false ) // count == 1 |
|
109 | + else if (($result = reset($productItems)) !== false) // count == 1 |
|
110 | 110 | { |
111 | 111 | $productItem = $result; |
112 | - $orderBaseProductItem->setProductCode( $productItem->getCode() ); |
|
112 | + $orderBaseProductItem->setProductCode($productItem->getCode()); |
|
113 | 113 | |
114 | - $subprices = $productItem->getRefItems( 'price', 'default', 'default' ); |
|
114 | + $subprices = $productItem->getRefItems('price', 'default', 'default'); |
|
115 | 115 | |
116 | - if( !empty( $subprices ) ) { |
|
116 | + if (!empty($subprices)) { |
|
117 | 117 | $prices = $subprices; |
118 | 118 | } |
119 | 119 | |
120 | - $submedia = $productItem->getRefItems( 'media', 'default', 'default' ); |
|
120 | + $submedia = $productItem->getRefItems('media', 'default', 'default'); |
|
121 | 121 | |
122 | - if( ( $mediaItem = reset( $submedia ) ) !== false ) { |
|
123 | - $orderBaseProductItem->setMediaUrl( $mediaItem->getPreview() ); |
|
122 | + if (($mediaItem = reset($submedia)) !== false) { |
|
123 | + $orderBaseProductItem->setMediaUrl($mediaItem->getPreview()); |
|
124 | 124 | } |
125 | 125 | |
126 | - $orderProductAttrManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order/base/product/attribute' ); |
|
127 | - $variantAttributes = $productItem->getRefItems( 'attribute', null, 'variant' ); |
|
126 | + $orderProductAttrManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'order/base/product/attribute'); |
|
127 | + $variantAttributes = $productItem->getRefItems('attribute', null, 'variant'); |
|
128 | 128 | |
129 | - foreach( $this->getAttributes( array_keys( $variantAttributes ), array( 'text' ) ) as $attrItem ) |
|
129 | + foreach ($this->getAttributes(array_keys($variantAttributes), array('text')) as $attrItem) |
|
130 | 130 | { |
131 | 131 | $orderAttributeItem = $orderProductAttrManager->createItem(); |
132 | - $orderAttributeItem->copyFrom( $attrItem ); |
|
133 | - $orderAttributeItem->setType( 'variant' ); |
|
132 | + $orderAttributeItem->copyFrom($attrItem); |
|
133 | + $orderAttributeItem->setType('variant'); |
|
134 | 134 | |
135 | 135 | $attr[] = $orderAttributeItem; |
136 | 136 | } |
137 | 137 | } |
138 | - else if( !isset( $options['variant'] ) || $options['variant'] != false ) // count == 0 |
|
138 | + else if (!isset($options['variant']) || $options['variant'] != false) // count == 0 |
|
139 | 139 | { |
140 | - $msg = sprintf( 'No article found for selected attributes and product ID "%1$s"', $productItem->getId() ); |
|
141 | - throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg ); |
|
140 | + $msg = sprintf('No article found for selected attributes and product ID "%1$s"', $productItem->getId()); |
|
141 | + throw new \Aimeos\Controller\Frontend\Basket\Exception($msg); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | return $attr; |
@@ -41,14 +41,14 @@ discard block |
||
41 | 41 | * @param string $stocktype Unique code of the stock type to deliver the products from |
42 | 42 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If the product isn't available |
43 | 43 | */ |
44 | - public function addProduct( $prodid, $quantity = 1, array $options = [], array $variantAttributeIds = [], |
|
44 | + public function addProduct($prodid, $quantity = 1, array $options = [], array $variantAttributeIds = [], |
|
45 | 45 | array $configAttributeIds = [], array $hiddenAttributeIds = [], array $customAttributeValues = [], |
46 | - $stocktype = 'default' ) |
|
46 | + $stocktype = 'default') |
|
47 | 47 | { |
48 | 48 | $context = $this->getContext(); |
49 | - $productManager = \Aimeos\MShop\Factory::createManager( $context, 'product' ); |
|
49 | + $productManager = \Aimeos\MShop\Factory::createManager($context, 'product'); |
|
50 | 50 | |
51 | - if( $productManager->getItem( $prodid, [], true )->getType() !== 'bundle' ) |
|
51 | + if ($productManager->getItem($prodid, [], true)->getType() !== 'bundle') |
|
52 | 52 | { |
53 | 53 | return $this->getController()->addProduct( |
54 | 54 | $prodid, $quantity, $options, $variantAttributeIds, $configAttributeIds, |
@@ -57,29 +57,29 @@ discard block |
||
57 | 57 | } |
58 | 58 | |
59 | 59 | $attributeMap = [ |
60 | - 'custom' => array_keys( $customAttributeValues ), |
|
61 | - 'config' => array_keys( $configAttributeIds ), |
|
60 | + 'custom' => array_keys($customAttributeValues), |
|
61 | + 'config' => array_keys($configAttributeIds), |
|
62 | 62 | 'hidden' => $hiddenAttributeIds, |
63 | 63 | ]; |
64 | - $this->checkListRef( $prodid, 'attribute', $attributeMap ); |
|
64 | + $this->checkListRef($prodid, 'attribute', $attributeMap); |
|
65 | 65 | |
66 | 66 | |
67 | - $productItem = $productManager->getItem( $prodid, array( 'media', 'supplier', 'price', 'product', 'text' ), true ); |
|
68 | - $prices = $productItem->getRefItems( 'price', 'default', 'default' ); |
|
67 | + $productItem = $productManager->getItem($prodid, array('media', 'supplier', 'price', 'product', 'text'), true); |
|
68 | + $prices = $productItem->getRefItems('price', 'default', 'default'); |
|
69 | 69 | |
70 | - $orderBaseProductItem = \Aimeos\MShop\Factory::createManager( $context, 'order/base/product' )->createItem(); |
|
71 | - $orderBaseProductItem->copyFrom( $productItem )->setQuantity( $quantity )->setStockType( $stocktype ); |
|
70 | + $orderBaseProductItem = \Aimeos\MShop\Factory::createManager($context, 'order/base/product')->createItem(); |
|
71 | + $orderBaseProductItem->copyFrom($productItem)->setQuantity($quantity)->setStockType($stocktype); |
|
72 | 72 | |
73 | - $this->addBundleProducts( $orderBaseProductItem, $productItem, $variantAttributeIds, $stocktype ); |
|
73 | + $this->addBundleProducts($orderBaseProductItem, $productItem, $variantAttributeIds, $stocktype); |
|
74 | 74 | |
75 | - $attr = $this->getOrderProductAttributes( 'custom', array_keys( $customAttributeValues ), $customAttributeValues ); |
|
76 | - $attr = array_merge( $attr, $this->getOrderProductAttributes( 'config', array_keys( $configAttributeIds ), [], $configAttributeIds ) ); |
|
77 | - $attr = array_merge( $attr, $this->getOrderProductAttributes( 'hidden', $hiddenAttributeIds ) ); |
|
75 | + $attr = $this->getOrderProductAttributes('custom', array_keys($customAttributeValues), $customAttributeValues); |
|
76 | + $attr = array_merge($attr, $this->getOrderProductAttributes('config', array_keys($configAttributeIds), [], $configAttributeIds)); |
|
77 | + $attr = array_merge($attr, $this->getOrderProductAttributes('hidden', $hiddenAttributeIds)); |
|
78 | 78 | |
79 | - $orderBaseProductItem->setAttributes( $attr ); |
|
80 | - $orderBaseProductItem->setPrice( $this->calcPrice( $orderBaseProductItem, $prices, $quantity ) ); |
|
79 | + $orderBaseProductItem->setAttributes($attr); |
|
80 | + $orderBaseProductItem->setPrice($this->calcPrice($orderBaseProductItem, $prices, $quantity)); |
|
81 | 81 | |
82 | - $this->getController()->get()->addProduct( $orderBaseProductItem ); |
|
82 | + $this->getController()->get()->addProduct($orderBaseProductItem); |
|
83 | 83 | $this->getController()->save(); |
84 | 84 | } |
85 | 85 | |
@@ -92,43 +92,43 @@ discard block |
||
92 | 92 | * @param array $variantAttributeIds List of product variant attribute IDs |
93 | 93 | * @param string $stocktype |
94 | 94 | */ |
95 | - protected function addBundleProducts( \Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem, |
|
96 | - \Aimeos\MShop\Product\Item\Iface $productItem, array $variantAttributeIds, $stocktype ) |
|
95 | + protected function addBundleProducts(\Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem, |
|
96 | + \Aimeos\MShop\Product\Item\Iface $productItem, array $variantAttributeIds, $stocktype) |
|
97 | 97 | { |
98 | 98 | $quantity = $orderBaseProductItem->getQuantity(); |
99 | 99 | $products = $subProductIds = $orderProducts = []; |
100 | - $orderProductManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order/base/product' ); |
|
100 | + $orderProductManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'order/base/product'); |
|
101 | 101 | |
102 | - foreach( $productItem->getRefItems( 'product', null, 'default' ) as $item ) { |
|
102 | + foreach ($productItem->getRefItems('product', null, 'default') as $item) { |
|
103 | 103 | $subProductIds[] = $item->getId(); |
104 | 104 | } |
105 | 105 | |
106 | - if( count( $subProductIds ) > 0 ) |
|
106 | + if (count($subProductIds) > 0) |
|
107 | 107 | { |
108 | - $productManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product' ); |
|
108 | + $productManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product'); |
|
109 | 109 | |
110 | - $search = $productManager->createSearch( true ); |
|
110 | + $search = $productManager->createSearch(true); |
|
111 | 111 | $expr = array( |
112 | - $search->compare( '==', 'product.id', $subProductIds ), |
|
112 | + $search->compare('==', 'product.id', $subProductIds), |
|
113 | 113 | $search->getConditions(), |
114 | 114 | ); |
115 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
115 | + $search->setConditions($search->combine('&&', $expr)); |
|
116 | 116 | |
117 | - $products = $productManager->searchItems( $search, array( 'attribute', 'media', 'price', 'text' ) ); |
|
117 | + $products = $productManager->searchItems($search, array('attribute', 'media', 'price', 'text')); |
|
118 | 118 | } |
119 | 119 | |
120 | - foreach( $products as $product ) |
|
120 | + foreach ($products as $product) |
|
121 | 121 | { |
122 | - $prices = $product->getRefItems( 'price', 'default', 'default' ); |
|
122 | + $prices = $product->getRefItems('price', 'default', 'default'); |
|
123 | 123 | |
124 | 124 | $orderProduct = $orderProductManager->createItem(); |
125 | - $orderProduct->copyFrom( $product ); |
|
126 | - $orderProduct->setStockType( $stocktype ); |
|
127 | - $orderProduct->setPrice( $this->calcPrice( $orderProduct, $prices, $quantity ) ); |
|
125 | + $orderProduct->copyFrom($product); |
|
126 | + $orderProduct->setStockType($stocktype); |
|
127 | + $orderProduct->setPrice($this->calcPrice($orderProduct, $prices, $quantity)); |
|
128 | 128 | |
129 | 129 | $orderProducts[] = $orderProduct; |
130 | 130 | } |
131 | 131 | |
132 | - $orderBaseProductItem->setProducts( $orderProducts ); |
|
132 | + $orderBaseProductItem->setProducts($orderProducts); |
|
133 | 133 | } |
134 | 134 | } |