Completed
Push — master ( fe698d...b119a8 )
by Aimeos
02:38
created
controller/frontend/src/Controller/Frontend/Basket/Decorator/Select.php 1 patch
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -41,15 +41,15 @@  discard block
 block discarded – undo
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(), array $variantAttributeIds = array(),
44
+	public function addProduct($prodid, $quantity = 1, array $options = array(), array $variantAttributeIds = array(),
45 45
 		array $configAttributeIds = array(), array $hiddenAttributeIds = array(), array $customAttributeValues = array(),
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, array( 'media', 'supplier', 'price', 'product', 'text' ) );
49
+		$productManager = \Aimeos\MShop\Factory::createManager($context, 'product');
50
+		$productItem = $productManager->getItem($prodid, array('media', 'supplier', 'price', 'product', 'text'));
51 51
 
52
-		if( $productItem->getType() !== 'select' )
52
+		if ($productItem->getType() !== 'select')
53 53
 		{
54 54
 			return $this->getController()->addProduct(
55 55
 				$prodid, $quantity, $options, $variantAttributeIds, $configAttributeIds,
@@ -57,29 +57,29 @@  discard block
 block discarded – undo
57 57
 			);
58 58
 		}
59 59
 
60
-		$orderBaseProductItem = \Aimeos\MShop\Factory::createManager( $context, 'order/base/product' )->createItem();
61
-		$orderBaseProductItem->copyFrom( $productItem );
62
-		$orderBaseProductItem->setQuantity( $quantity );
63
-		$orderBaseProductItem->setStockType( $stocktype );
60
+		$orderBaseProductItem = \Aimeos\MShop\Factory::createManager($context, 'order/base/product')->createItem();
61
+		$orderBaseProductItem->copyFrom($productItem);
62
+		$orderBaseProductItem->setQuantity($quantity);
63
+		$orderBaseProductItem->setStockType($stocktype);
64 64
 
65
-		$prices = $productItem->getRefItems( 'price', 'default', 'default' );
66
-		$attr = $this->getVariantDetails( $orderBaseProductItem, $productItem, $prices, $variantAttributeIds, $options );
67
-		$prodIds = array( $prodid, $productItem->getId() );
65
+		$prices = $productItem->getRefItems('price', 'default', 'default');
66
+		$attr = $this->getVariantDetails($orderBaseProductItem, $productItem, $prices, $variantAttributeIds, $options);
67
+		$prodIds = array($prodid, $productItem->getId());
68 68
 
69
-		$priceManager = \Aimeos\MShop\Factory::createManager( $context, 'price' );
70
-		$price = $priceManager->getLowestPrice( $prices, $quantity );
69
+		$priceManager = \Aimeos\MShop\Factory::createManager($context, 'price');
70
+		$price = $priceManager->getLowestPrice($prices, $quantity);
71 71
 
72
-		$attr = array_merge( $attr, $this->createOrderProductAttributes( $price, $prodIds, $quantity, $configAttributeIds, 'config' ) );
73
-		$attr = array_merge( $attr, $this->createOrderProductAttributes( $price, $prodIds, $quantity, $hiddenAttributeIds, 'hidden' ) );
74
-		$attr = array_merge( $attr, $this->createOrderProductAttributes( $price, $prodIds, $quantity, array_keys( $customAttributeValues ), 'custom', $customAttributeValues ) );
72
+		$attr = array_merge($attr, $this->createOrderProductAttributes($price, $prodIds, $quantity, $configAttributeIds, 'config'));
73
+		$attr = array_merge($attr, $this->createOrderProductAttributes($price, $prodIds, $quantity, $hiddenAttributeIds, 'hidden'));
74
+		$attr = array_merge($attr, $this->createOrderProductAttributes($price, $prodIds, $quantity, array_keys($customAttributeValues), 'custom', $customAttributeValues));
75 75
 
76 76
 		// remove product rebate of original price in favor to rebates granted for the order
77
-		$price->setRebate( '0.00' );
77
+		$price->setRebate('0.00');
78 78
 
79
-		$orderBaseProductItem->setPrice( $price );
80
-		$orderBaseProductItem->setAttributes( $attr );
79
+		$orderBaseProductItem->setPrice($price);
80
+		$orderBaseProductItem->setAttributes($attr);
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
 block discarded – undo
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 = array();
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;
Please login to merge, or discard this patch.