1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2025 |
6
|
|
|
* @package Controller |
7
|
|
|
* @subpackage Frontend |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Controller\Frontend\Basket\Decorator; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Bundle product handling |
16
|
|
|
* |
17
|
|
|
* @package Controller |
18
|
|
|
* @subpackage Frontend |
19
|
|
|
*/ |
20
|
|
|
class Bundle |
21
|
|
|
extends \Aimeos\Controller\Frontend\Basket\Decorator\Base |
22
|
|
|
implements \Aimeos\Controller\Frontend\Basket\Iface, \Aimeos\Controller\Frontend\Common\Decorator\Iface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Adds a product to the basket of the customer stored in the session |
26
|
|
|
* |
27
|
|
|
* @param \Aimeos\MShop\Product\Item\Iface $product Product to add including texts, media, prices, attributes, etc. |
28
|
|
|
* @param float $quantity Amount of products that should by added |
29
|
|
|
* @param array $variant List of variant-building attribute IDs that identify an article in a selection product |
30
|
|
|
* @param array $config List of configurable attribute IDs the customer has chosen from |
31
|
|
|
* @param array $custom Associative list of attribute IDs as keys and arbitrary values that will be added to the ordered product |
32
|
|
|
* @param string $stocktype Unique code of the stock type to deliver the products from |
33
|
|
|
* @param string|null $supplierid Unique supplier ID the product is from |
34
|
|
|
* @param string|null $siteid Unique site ID the product is from or null for siteid of the product item |
35
|
|
|
* @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface |
36
|
|
|
* @throws \Aimeos\Controller\Frontend\Basket\Exception If the product isn't available |
37
|
|
|
*/ |
38
|
|
|
public function addProduct( \Aimeos\MShop\Product\Item\Iface $product, float $quantity = 1, |
39
|
|
|
array $variant = [], array $config = [], array $custom = [], string $stocktype = 'default', ?string $siteId = null |
40
|
|
|
) : \Aimeos\Controller\Frontend\Basket\Iface |
41
|
|
|
{ |
42
|
|
|
if( $product->getType() !== 'bundle' ) |
43
|
|
|
{ |
44
|
|
|
$this->getController()->addProduct( $product, $quantity, $variant, $config, $custom, $stocktype, $siteId ); |
45
|
|
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$quantity = $this->call( 'checkQuantity', $product, $quantity ); |
49
|
|
|
$this->call( 'checkAttributes', [$product], 'custom', array_keys( $custom ) ); |
50
|
|
|
$this->call( 'checkAttributes', [$product], 'config', array_keys( $config ) ); |
51
|
|
|
|
52
|
|
|
$prices = $product->getRefItems( 'price', 'default', 'default' ); |
53
|
|
|
$hidden = $product->getRefItems( 'attribute', null, 'hidden' ); |
54
|
|
|
|
55
|
|
|
$custAttr = $this->call( 'getOrderProductAttributes', 'custom', array_keys( $custom ), $custom ); |
56
|
|
|
$confAttr = $this->call( 'getOrderProductAttributes', 'config', array_keys( $config ), [], $config ); |
57
|
|
|
$hideAttr = $this->call( 'getOrderProductAttributes', 'hidden', $hidden->keys()->toArray() ); |
58
|
|
|
|
59
|
|
|
$orderProductItem = \Aimeos\MShop::create( $this->context(), 'order' ) |
60
|
|
|
->createProduct() |
|
|
|
|
61
|
|
|
->copyFrom( $product ) |
62
|
|
|
->setQuantity( $quantity ) |
63
|
|
|
->setStockType( $stocktype ) |
64
|
|
|
->setSiteId( $siteId ?: $product->getSiteId() ) |
65
|
|
|
->setAttributeItems( array_merge( $custAttr, $confAttr, $hideAttr ) ) |
66
|
|
|
->setProducts( $this->getBundleProducts( $product, $quantity, $stocktype ) ); |
67
|
|
|
|
68
|
|
|
$price = $this->call( 'calcPrice', $orderProductItem, $prices, $quantity ); |
69
|
|
|
$orderProductItem |
70
|
|
|
->setPrice( $price ) |
71
|
|
|
->setSiteId( $siteId ?: $price->getSiteId() ) |
72
|
|
|
->setVendor( $this->getVendor( $siteId ?: $price->getSiteId() ) ); |
73
|
|
|
|
74
|
|
|
$this->getController()->get()->addProduct( $orderProductItem ); |
75
|
|
|
$this->getController()->save(); |
76
|
|
|
|
77
|
|
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Adds the bundled products to the order product item. |
83
|
|
|
* |
84
|
|
|
* @param \Aimeos\MShop\Product\Item\Iface $product Bundle product item |
85
|
|
|
* @param float $quantity Amount of products that should by added |
86
|
|
|
* @param string $stocktype Unique code of the stock type to deliver the products from |
87
|
|
|
* @return \Aimeos\MShop\Order\Item\Product\Iface[] List of order product item from bundle |
88
|
|
|
*/ |
89
|
|
|
protected function getBundleProducts( \Aimeos\MShop\Product\Item\Iface $product, float $quantity, string $stocktype ) : array |
90
|
|
|
{ |
91
|
|
|
$orderProducts = []; |
92
|
|
|
$orderManager = \Aimeos\MShop::create( $this->context(), 'order' ); |
93
|
|
|
|
94
|
|
|
foreach( $product->getRefItems( 'product', null, 'default' ) as $item ) |
95
|
|
|
{ |
96
|
|
|
$prices = $item->getRefItems( 'price', 'default', 'default' ); |
97
|
|
|
$orderProduct = $orderManager->createProduct() |
98
|
|
|
->copyFrom( $item ) |
99
|
|
|
->setStockType( $stocktype ) |
100
|
|
|
->setParentProductId( $product->getId() ); |
101
|
|
|
|
102
|
|
|
$orderProducts[] = $orderProduct->setPrice( $this->call( 'calcPrice', $orderProduct, $prices, $quantity ) ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
return $orderProducts; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.