1 | <?php |
||
21 | class Standard |
||
22 | extends Base |
||
23 | implements Iface, \Aimeos\Controller\Frontend\Common\Iface |
||
24 | { |
||
25 | private $baskets = []; |
||
26 | private $domainManager; |
||
27 | private $type = 'default'; |
||
28 | |||
29 | |||
30 | /** |
||
31 | * Initializes the frontend controller. |
||
32 | * |
||
33 | * @param \Aimeos\MShop\Context\Item\Iface $context Object storing the required instances for manaing databases |
||
34 | * connections, logger, session, etc. |
||
35 | */ |
||
36 | public function __construct( \Aimeos\MShop\Context\Item\Iface $context ) |
||
42 | |||
43 | |||
44 | /** |
||
45 | * Empties the basket and removing all products, addresses, services, etc. |
||
46 | * |
||
47 | * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object |
||
48 | */ |
||
49 | public function clear() |
||
56 | |||
57 | |||
58 | /** |
||
59 | * Returns the basket object. |
||
60 | * |
||
61 | * @return \Aimeos\MShop\Order\Item\Base\Iface Basket holding products, addresses and delivery/payment options |
||
62 | */ |
||
63 | public function get() |
||
73 | |||
74 | |||
75 | /** |
||
76 | * Explicitely persists the basket content |
||
77 | * |
||
78 | * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object |
||
79 | */ |
||
80 | public function save() |
||
88 | |||
89 | |||
90 | /** |
||
91 | * Sets the new basket type |
||
92 | * |
||
93 | * @param string $type Basket type |
||
94 | * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object |
||
95 | */ |
||
96 | public function setType( $type ) |
||
101 | |||
102 | |||
103 | /** |
||
104 | * Creates a new order base object from the current basket |
||
105 | * |
||
106 | * @return \Aimeos\MShop\Order\Item\Base\Iface Order base object including products, addresses and services |
||
107 | */ |
||
108 | public function store() |
||
109 | { |
||
110 | $total = 0; |
||
111 | $context = $this->getContext(); |
||
112 | $config = $context->getConfig(); |
||
113 | |||
114 | /** controller/frontend/basket/limit-count |
||
115 | * Maximum number of orders within the time frame |
||
116 | * |
||
117 | * Creating new orders is limited to avoid abuse and mitigate denial of |
||
118 | * service attacks. The number of orders created within the time frame |
||
119 | * configured by "controller/frontend/basket/limit-seconds" are counted |
||
120 | * before a new order of the same user (either logged in or identified |
||
121 | * by the IP address) is created. If the number of orders is higher than |
||
122 | * the configured value, an error message will be shown to the user |
||
123 | * instead of creating a new order. |
||
124 | * |
||
125 | * @param integer Number of orders allowed within the time frame |
||
126 | * @since 2017.05 |
||
127 | * @category Developer |
||
128 | * @see controller/frontend/basket/limit-seconds |
||
129 | */ |
||
130 | $count = $config->get( 'controller/frontend/basket/limit-count', 5 ); |
||
131 | |||
132 | /** controller/frontend/basket/limit-seconds |
||
133 | * Order limitation time frame in seconds |
||
134 | * |
||
135 | * Creating new orders is limited to avoid abuse and mitigate denial of |
||
136 | * service attacks. Within the configured time frame, only a limited |
||
137 | * number of orders can be created. All orders of the current user |
||
138 | * (either logged in or identified by the IP address) within the last X |
||
139 | * seconds are counted. If the total value is higher then the number |
||
140 | * configured in "controller/frontend/basket/limit-count", an error |
||
141 | * message will be shown to the user instead of creating a new order. |
||
142 | * |
||
143 | * @param integer Number of seconds to check orders within |
||
144 | * @since 2017.05 |
||
145 | * @category Developer |
||
146 | * @see controller/frontend/basket/limit-count |
||
147 | */ |
||
148 | $seconds = $config->get( 'controller/frontend/basket/limit-seconds', 300 ); |
||
149 | |||
150 | $search = $this->domainManager->createSearch(); |
||
151 | $expr = [ |
||
152 | $search->compare( '==', 'order.base.editor', $context->getEditor() ), |
||
153 | $search->compare( '>=', 'order.base.ctime', date( 'Y-m-d H:i:s', time() - $seconds ) ), |
||
154 | ]; |
||
155 | $search->setConditions( $search->combine( '&&', $expr ) ); |
||
156 | $search->setSlice( 0, 0 ); |
||
157 | |||
158 | $this->domainManager->searchItems( $search, [], $total ); |
||
159 | |||
160 | if( $total > $count ) |
||
161 | { |
||
162 | $msg = $context->getI18n()->dt( 'controller/frontend', 'Temporary order limit reached' ); |
||
163 | throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg ); |
||
164 | } |
||
165 | |||
166 | |||
167 | $basket = $this->get()->finish(); |
||
168 | $basket->setCustomerId( (string) $context->getUserId() ); |
||
169 | |||
170 | $this->domainManager->begin(); |
||
171 | $this->domainManager->store( $basket ); |
||
172 | $this->domainManager->commit(); |
||
173 | |||
174 | return $basket; |
||
175 | } |
||
176 | |||
177 | |||
178 | /** |
||
179 | * Returns the order base object for the given ID |
||
180 | * |
||
181 | * @param string $id Unique ID of the order base object |
||
182 | * @param integer $parts Constants which parts of the order base object should be loaded |
||
183 | * @param boolean $default True to add default criteria (user logged in), false if not |
||
184 | * @return \Aimeos\MShop\Order\Item\Base\Iface Order base object including the given parts |
||
185 | */ |
||
186 | public function load( $id, $parts = \Aimeos\MShop\Order\Item\Base\Base::PARTS_ALL, $default = true ) |
||
187 | { |
||
188 | return $this->domainManager->load( $id, $parts, false, $default ); |
||
189 | } |
||
190 | |||
191 | |||
192 | /** |
||
193 | * Adds a categorized product to the basket of the user stored in the session. |
||
194 | * |
||
195 | * @param string $prodid ID of the base product to add |
||
196 | * @param integer $quantity Amount of products that should by added |
||
197 | * @param array $variantAttributeIds List of variant-building attribute IDs that identify a specific product |
||
198 | * in a selection products |
||
199 | * @param array $configAttributeIds List of attribute IDs that doesn't identify a specific product in a |
||
200 | * selection of products but are stored together with the product (e.g. for configurable products) |
||
201 | * @param array $hiddenAttributeIds List of attribute IDs that should be stored along with the product in the order |
||
202 | * @param array $customAttributeValues Associative list of attribute IDs and arbitrary values that should be stored |
||
203 | * along with the product in the order |
||
204 | * @param string $stocktype Unique code of the stock type to deliver the products from |
||
205 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If the product isn't available |
||
206 | */ |
||
207 | public function addProduct( $prodid, $quantity = 1, $stocktype = 'default', array $variantAttributeIds = [], |
||
208 | array $configAttributeIds = [], array $hiddenAttributeIds = [], array $customAttributeValues = [] ) |
||
209 | { |
||
210 | $attributeMap = [ |
||
211 | 'custom' => array_keys( $customAttributeValues ), |
||
212 | 'config' => array_keys( $configAttributeIds ), |
||
213 | 'hidden' => $hiddenAttributeIds, |
||
214 | ]; |
||
215 | $this->checkListRef( $prodid, 'attribute', $attributeMap ); |
||
216 | |||
217 | |||
218 | $context = $this->getContext(); |
||
219 | $productManager = \Aimeos\MShop\Factory::createManager( $context, 'product' ); |
||
220 | $productItem = $productManager->getItem( $prodid, array( 'media', 'supplier', 'price', 'product', 'text' ), true ); |
||
221 | $prices = $productItem->getRefItems( 'price', 'default', 'default' ); |
||
222 | |||
223 | $orderBaseProductItem = \Aimeos\MShop\Factory::createManager( $context, 'order/base/product' )->createItem(); |
||
224 | $orderBaseProductItem->copyFrom( $productItem )->setQuantity( $quantity )->setStockType( $stocktype ); |
||
225 | |||
226 | $attr = $this->getOrderProductAttributes( 'custom', array_keys( $customAttributeValues ), $customAttributeValues ); |
||
227 | $attr = array_merge( $attr, $this->getOrderProductAttributes( 'config', array_keys( $configAttributeIds ), [], $configAttributeIds ) ); |
||
228 | $attr = array_merge( $attr, $this->getOrderProductAttributes( 'hidden', $hiddenAttributeIds ) ); |
||
229 | |||
230 | $orderBaseProductItem->setAttributes( $attr ); |
||
231 | $orderBaseProductItem->setPrice( $this->calcPrice( $orderBaseProductItem, $prices, $quantity ) ); |
||
232 | |||
233 | $this->get()->addProduct( $orderBaseProductItem ); |
||
234 | $this->save(); |
||
235 | } |
||
236 | |||
237 | |||
238 | /** |
||
239 | * Deletes a product item from the basket. |
||
240 | * |
||
241 | * @param integer $position Position number (key) of the order product item |
||
242 | */ |
||
243 | public function deleteProduct( $position ) |
||
256 | |||
257 | |||
258 | /** |
||
259 | * Edits the quantity of a product item in the basket. |
||
260 | * |
||
261 | * @param integer $position Position number (key) of the order product item |
||
262 | * @param integer $quantity New quantiy of the product item |
||
263 | * @param string[] $configAttributeCodes Codes of the product config attributes that should be REMOVED |
||
264 | */ |
||
265 | public function editProduct( $position, $quantity, array $configAttributeCodes = [] ) |
||
294 | |||
295 | |||
296 | /** |
||
297 | * Adds the given coupon code and updates the basket. |
||
298 | * |
||
299 | * @param string $code Coupon code entered by the user |
||
300 | * @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid or not allowed |
||
301 | */ |
||
302 | public function addCoupon( $code ) |
||
357 | |||
358 | |||
359 | /** |
||
360 | * Removes the given coupon code and its effects from the basket. |
||
361 | * |
||
362 | * @param string $code Coupon code entered by the user |
||
363 | * @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid |
||
364 | */ |
||
365 | public function deleteCoupon( $code ) |
||
385 | |||
386 | |||
387 | /** |
||
388 | * Sets the address of the customer in the basket. |
||
389 | * |
||
390 | * @param string $type Address type constant from \Aimeos\MShop\Order\Item\Base\Address\Base |
||
391 | * @param \Aimeos\MShop\Common\Item\Address\Iface|array|null $value Address object or array with key/value pairs of address or null to remove address from basket |
||
392 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If the billing or delivery address is not of any required type of |
||
393 | * if one of the keys is invalid when using an array with key/value pairs |
||
394 | */ |
||
395 | public function setAddress( $type, $value ) |
||
423 | |||
424 | |||
425 | /** |
||
426 | * Adds the delivery/payment service item based on the service ID. |
||
427 | * |
||
428 | * @param string $type Service type code like 'payment' or 'delivery' |
||
429 | * @param string $id|null Unique ID of the service item or null to remove it |
||
|
|||
430 | * @param array $attributes Associative list of key/value pairs containing the attributes selected or |
||
431 | * entered by the customer when choosing one of the delivery or payment options |
||
432 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If there is no price to the service item attached |
||
433 | */ |
||
434 | public function addService( $type, $id, array $attributes = [] ) |
||
472 | |||
473 | |||
474 | /** |
||
475 | * Removes the delivery or payment service items from the basket |
||
476 | * |
||
477 | * @param string $type Service type code like 'payment' or 'delivery' |
||
478 | */ |
||
479 | public function deleteService( $type ) |
||
484 | |||
485 | |||
486 | /** |
||
487 | * Fills the order address object with the values from the array. |
||
488 | * |
||
489 | * @param \Aimeos\MShop\Order\Item\Base\Address\Iface $address Address item to store the values into |
||
490 | * @param array $map Associative array of key/value pairs. The keys must be the same as when calling toArray() from |
||
491 | * an address item. |
||
492 | * @throws \Aimeos\Controller\Frontend\Basket\Exception |
||
493 | */ |
||
494 | protected function setAddressFromArray( \Aimeos\MShop\Order\Item\Base\Address\Iface $address, array $map ) |
||
508 | } |
||
509 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.