1 | <?php |
||
2 | |||
3 | /** |
||
4 | * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
||
5 | * @copyright Metaways Infosystems GmbH, 2011 |
||
6 | * @copyright Aimeos (aimeos.org), 2015-2018 |
||
7 | * @package MShop |
||
8 | * @subpackage Product |
||
9 | */ |
||
10 | |||
11 | |||
12 | namespace Aimeos\MShop\Order\Manager\Base\Product\Attribute; |
||
13 | |||
14 | |||
15 | /** |
||
16 | * Default order manager base product attribute. |
||
17 | * |
||
18 | * @package MShop |
||
19 | * @subpackage Order |
||
20 | */ |
||
21 | class Standard |
||
22 | extends \Aimeos\MShop\Common\Manager\Base |
||
23 | implements \Aimeos\MShop\Order\Manager\Base\Product\Attribute\Iface, \Aimeos\MShop\Common\Manager\Factory\Iface |
||
24 | { |
||
25 | private $searchConfig = array( |
||
26 | 'order.base.product.attribute.id' => array( |
||
27 | 'code' => 'order.base.product.attribute.id', |
||
28 | 'internalcode' => 'mordbaprat."id"', |
||
29 | 'internaldeps' => array( 'LEFT JOIN "mshop_order_base_product_attr" AS mordbaprat ON ( mordbapr."id" = mordbaprat."ordprodid" )' ), |
||
30 | 'label' => 'Product attribute ID', |
||
31 | 'type' => 'integer', |
||
32 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT, |
||
33 | 'public' => false, |
||
34 | ), |
||
35 | 'order.base.product.attribute.siteid' => array( |
||
36 | 'code' => 'order.base.product.attribute.siteid', |
||
37 | 'internalcode' => 'mordbaprat."siteid"', |
||
38 | 'label' => 'Product attribute site ID', |
||
39 | 'type' => 'integer', |
||
40 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT, |
||
41 | 'public' => false, |
||
42 | ), |
||
43 | 'order.base.product.attribute.attributeid' => array( |
||
44 | 'code' => 'order.base.product.attribute.attributeid', |
||
45 | 'internalcode' => 'mordbaprat."attrid"', |
||
46 | 'label' => 'Product attribute original ID', |
||
47 | 'type' => 'string', |
||
48 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
||
49 | 'public' => false, |
||
50 | ), |
||
51 | 'order.base.product.attribute.parentid' => array( |
||
52 | 'code' => 'order.base.product.attribute.parentid', |
||
53 | 'internalcode' => 'mordbaprat."ordprodid"', |
||
54 | 'label' => 'Product ID', |
||
55 | 'type' => 'integer', |
||
56 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT, |
||
57 | 'public' => false, |
||
58 | ), |
||
59 | 'order.base.product.attribute.name' => array( |
||
60 | 'code' => 'order.base.product.attribute.name', |
||
61 | 'internalcode' => 'mordbaprat."name"', |
||
62 | 'label' => 'Product attribute name', |
||
63 | 'type' => 'string', |
||
64 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
||
65 | ), |
||
66 | 'order.base.product.attribute.value' => array( |
||
67 | 'code' => 'order.base.product.attribute.value', |
||
68 | 'internalcode' => 'mordbaprat."value"', |
||
69 | 'label' => 'Product attribute value', |
||
70 | 'type' => 'string', |
||
71 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
||
72 | ), |
||
73 | 'order.base.product.attribute.code' => array( |
||
74 | 'code' => 'order.base.product.attribute.code', |
||
75 | 'internalcode' => 'mordbaprat."code"', |
||
76 | 'label' => 'Product attribute code', |
||
77 | 'type' => 'string', |
||
78 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
||
79 | ), |
||
80 | 'order.base.product.attribute.type' => array( |
||
81 | 'code' => 'order.base.product.attribute.type', |
||
82 | 'internalcode' => 'mordbaprat."type"', |
||
83 | 'label' => 'Product attribute type', |
||
84 | 'type' => 'string', |
||
85 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
||
86 | ), |
||
87 | 'order.base.product.attribute.quantity' => array( |
||
88 | 'code' => 'order.base.product.attribute.quantity', |
||
89 | 'internalcode' => 'mordbaprat."quantity"', |
||
90 | 'label' => 'Product attribute quantity', |
||
91 | 'type' => 'integer', |
||
92 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT, |
||
93 | ), |
||
94 | 'order.base.product.attribute.ctime' => array( |
||
95 | 'code' => 'order.base.product.attribute.ctime', |
||
96 | 'internalcode' => 'mordbaprat."ctime"', |
||
97 | 'label' => 'Product attribute create date/time', |
||
98 | 'type' => 'datetime', |
||
99 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
||
100 | 'public' => false, |
||
101 | ), |
||
102 | 'order.base.product.attribute.mtime' => array( |
||
103 | 'code' => 'order.base.product.attribute.mtime', |
||
104 | 'internalcode' => 'mordbaprat."mtime"', |
||
105 | 'label' => 'Product attribute modify date/time', |
||
106 | 'type' => 'datetime', |
||
107 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
||
108 | 'public' => false, |
||
109 | ), |
||
110 | 'order.base.product.attribute.editor' => array( |
||
111 | 'code' => 'order.base.product.attribute.editor', |
||
112 | 'internalcode' => 'mordbaprat."editor"', |
||
113 | 'label' => 'Product attribute editor', |
||
114 | 'type' => 'string', |
||
115 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
||
116 | 'public' => false, |
||
117 | ), |
||
118 | ); |
||
119 | |||
120 | |||
121 | /** |
||
122 | * Initializes the object. |
||
123 | * |
||
124 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
125 | */ |
||
126 | public function __construct( \Aimeos\MShop\Context\Item\Iface $context ) |
||
127 | { |
||
128 | parent::__construct( $context ); |
||
129 | $this->setResourceName( 'db-order' ); |
||
130 | } |
||
131 | |||
132 | |||
133 | /** |
||
134 | * Counts the number items that are available for the values of the given key. |
||
135 | * |
||
136 | * @param \Aimeos\MW\Criteria\Iface $search Search criteria |
||
137 | * @param string $key Search key to aggregate items for |
||
138 | * @return array List of the search keys as key and the number of counted items as value |
||
139 | * @todo 2018.01 Add optional parameters to interface |
||
140 | */ |
||
141 | public function aggregate( \Aimeos\MW\Criteria\Iface $search, $key, $value = null, $type = null ) |
||
142 | { |
||
143 | /** mshop/order/manager/base/product/attribute/standard/aggregate/mysql |
||
144 | * Counts the number of records grouped by the values in the key column and matched by the given criteria |
||
145 | * |
||
146 | * @see mshop/order/manager/base/product/attribute/standard/aggregate/ansi |
||
147 | */ |
||
148 | |||
149 | /** mshop/order/manager/base/product/attribute/standard/aggregate/ansi |
||
150 | * Counts the number of records grouped by the values in the key column and matched by the given criteria |
||
151 | * |
||
152 | * Groups all records by the values in the key column and counts their |
||
153 | * occurence. The matched records can be limited by the given criteria |
||
154 | * from the order database. The records must be from one of the sites |
||
155 | * that are configured via the context item. If the current site is part |
||
156 | * of a tree of sites, the statement can count all records from the |
||
157 | * current site and the complete sub-tree of sites. |
||
158 | * |
||
159 | * As the records can normally be limited by criteria from sub-managers, |
||
160 | * their tables must be joined in the SQL context. This is done by |
||
161 | * using the "internaldeps" property from the definition of the ID |
||
162 | * column of the sub-managers. These internal dependencies specify |
||
163 | * the JOIN between the tables and the used columns for joining. The |
||
164 | * ":joins" placeholder is then replaced by the JOIN strings from |
||
165 | * the sub-managers. |
||
166 | * |
||
167 | * To limit the records matched, conditions can be added to the given |
||
168 | * criteria object. It can contain comparisons like column names that |
||
169 | * must match specific values which can be combined by AND, OR or NOT |
||
170 | * operators. The resulting string of SQL conditions replaces the |
||
171 | * ":cond" placeholder before the statement is sent to the database |
||
172 | * server. |
||
173 | * |
||
174 | * This statement doesn't return any records. Instead, it returns pairs |
||
175 | * of the different values found in the key column together with the |
||
176 | * number of records that have been found for that key values. |
||
177 | * |
||
178 | * The SQL statement should conform to the ANSI standard to be |
||
179 | * compatible with most relational database systems. This also |
||
180 | * includes using double quotes for table and column names. |
||
181 | * |
||
182 | * @param string SQL statement for aggregating order items |
||
183 | * @since 2014.09 |
||
184 | * @category Developer |
||
185 | * @see mshop/order/manager/base/product/attribute/standard/insert/ansi |
||
186 | * @see mshop/order/manager/base/product/attribute/standard/update/ansi |
||
187 | * @see mshop/order/manager/base/product/attribute/standard/newid/ansi |
||
188 | * @see mshop/order/manager/base/product/attribute/standard/delete/ansi |
||
189 | * @see mshop/order/manager/base/product/attribute/standard/search/ansi |
||
190 | * @see mshop/order/manager/base/product/attribute/standard/count/ansi |
||
191 | */ |
||
192 | $cfgkey = 'mshop/order/manager/base/product/attribute/standard/aggregate' . $type; |
||
193 | return $this->aggregateBase( $search, $key, $cfgkey, array( 'order.base.product.attribute' ), $value ); |
||
194 | } |
||
195 | |||
196 | |||
197 | /** |
||
198 | * Removes old entries from the storage. |
||
199 | * |
||
200 | * @param integer[] $siteids List of IDs for sites whose entries should be deleted |
||
201 | */ |
||
202 | public function cleanup( array $siteids ) |
||
203 | { |
||
204 | $path = 'mshop/order/manager/base/product/attribute/submanagers'; |
||
205 | foreach( $this->getContext()->getConfig()->get( $path, [] ) as $domain ) { |
||
206 | $this->getObject()->getSubManager( $domain )->cleanup( $siteids ); |
||
207 | } |
||
208 | |||
209 | $this->cleanupBase( $siteids, 'mshop/order/manager/base/product/attribute/standard/delete' ); |
||
210 | } |
||
211 | |||
212 | |||
213 | /** |
||
214 | * Creates a new empty item instance |
||
215 | * |
||
216 | * @param string|null Type the item should be created with |
||
217 | * @param string|null Domain of the type the item should be created with |
||
218 | * @param array $values Values the item should be initialized with |
||
219 | * @return \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface New order product attribute item object |
||
220 | */ |
||
221 | public function createItem( $type = null, $domain = null, array $values = [] ) |
||
222 | { |
||
223 | $values['order.base.product.attribute.siteid'] = $this->getContext()->getLocale()->getSiteId(); |
||
224 | return $this->createItemBase( $values ); |
||
225 | } |
||
226 | |||
227 | |||
228 | /** |
||
229 | * Returns an item for the given ID. |
||
230 | * |
||
231 | * @param integer $id ID of the item that should be retrieved |
||
232 | * @param string[] $ref List of domains to fetch list items and referenced items for |
||
233 | * @param boolean $default Add default criteria |
||
234 | * @return \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface Returns order base product attribute item of the given id |
||
235 | * @throws \Aimeos\MShop\Exception If item couldn't be found |
||
236 | */ |
||
237 | public function getItem( $id, array $ref = [], $default = false ) |
||
238 | { |
||
239 | return $this->getItemBase( 'order.base.product.attribute.id', $id, $ref, $default ); |
||
240 | } |
||
241 | |||
242 | |||
243 | /** |
||
244 | * Removes multiple items specified by ids in the array. |
||
245 | * |
||
246 | * @param array $ids List of IDs |
||
247 | */ |
||
248 | public function deleteItems( array $ids ) |
||
249 | { |
||
250 | /** mshop/order/manager/base/product/attribute/standard/delete/mysql |
||
251 | * Deletes the items matched by the given IDs from the database |
||
252 | * |
||
253 | * @see mshop/order/manager/base/product/attribute/standard/delete/ansi |
||
254 | */ |
||
255 | |||
256 | /** mshop/order/manager/base/product/attribute/standard/delete/ansi |
||
257 | * Deletes the items matched by the given IDs from the database |
||
258 | * |
||
259 | * Removes the records specified by the given IDs from the order database. |
||
260 | * The records must be from the site that is configured via the |
||
261 | * context item. |
||
262 | * |
||
263 | * The ":cond" placeholder is replaced by the name of the ID column and |
||
264 | * the given ID or list of IDs while the site ID is bound to the question |
||
265 | * mark. |
||
266 | * |
||
267 | * The SQL statement should conform to the ANSI standard to be |
||
268 | * compatible with most relational database systems. This also |
||
269 | * includes using double quotes for table and column names. |
||
270 | * |
||
271 | * @param string SQL statement for deleting items |
||
272 | * @since 2014.03 |
||
273 | * @category Developer |
||
274 | * @see mshop/order/manager/base/product/attribute/standard/insert/ansi |
||
275 | * @see mshop/order/manager/base/product/attribute/standard/update/ansi |
||
276 | * @see mshop/order/manager/base/product/attribute/standard/newid/ansi |
||
277 | * @see mshop/order/manager/base/product/attribute/standard/search/ansi |
||
278 | * @see mshop/order/manager/base/product/attribute/standard/count/ansi |
||
279 | */ |
||
280 | $path = 'mshop/order/manager/base/product/attribute/standard/delete'; |
||
281 | $this->deleteItemsBase( $ids, $path ); |
||
282 | } |
||
283 | |||
284 | |||
285 | /** |
||
286 | * Returns the available manager types |
||
287 | * |
||
288 | * @param boolean $withsub Return also the resource type of sub-managers if true |
||
289 | * @return array Type of the manager and submanagers, subtypes are separated by slashes |
||
290 | */ |
||
291 | public function getResourceType( $withsub = true ) |
||
292 | { |
||
293 | $path = 'mshop/order/manager/base/product/attribute/submanagers'; |
||
294 | |||
295 | return $this->getResourceTypeBase( 'order/base/product/attribute', $path, [], $withsub ); |
||
296 | } |
||
297 | |||
298 | |||
299 | /** |
||
300 | * Returns the attributes that can be used for searching. |
||
301 | * |
||
302 | * @param boolean $withsub Return also attributes of sub-managers if true |
||
303 | * @return array List of attributes implementing \Aimeos\MW\Criteria\Attribute\Iface |
||
304 | */ |
||
305 | public function getSearchAttributes( $withsub = true ) |
||
306 | { |
||
307 | /** mshop/order/manager/base/product/attribute/submanagers |
||
308 | * List of manager names that can be instantiated by the order base product attribute manager |
||
309 | * |
||
310 | * Managers provide a generic interface to the underlying storage. |
||
311 | * Each manager has or can have sub-managers caring about particular |
||
312 | * aspects. Each of these sub-managers can be instantiated by its |
||
313 | * parent manager using the getSubManager() method. |
||
314 | * |
||
315 | * The search keys from sub-managers can be normally used in the |
||
316 | * manager as well. It allows you to search for items of the manager |
||
317 | * using the search keys of the sub-managers to further limit the |
||
318 | * retrieved list of items. |
||
319 | * |
||
320 | * @param array List of sub-manager names |
||
321 | * @since 2014.03 |
||
322 | * @category Developer |
||
323 | */ |
||
324 | $path = 'mshop/order/manager/base/product/attribute/submanagers'; |
||
325 | |||
326 | return $this->getSearchAttributesBase( $this->searchConfig, $path, [], $withsub ); |
||
327 | } |
||
328 | |||
329 | |||
330 | /** |
||
331 | * Returns a new sub manager specified by its name. |
||
332 | * |
||
333 | * @param string $manager Name of the sub manager type in lower case |
||
334 | * @param string|null $name Name of the implementation, will be from configuration (or Default) if null |
||
335 | * @return \Aimeos\MShop\Common\Manager\Lists\Iface List manager |
||
336 | */ |
||
337 | public function getSubManager( $manager, $name = null ) |
||
338 | { |
||
339 | /** mshop/order/manager/base/product/attribute/name |
||
340 | * Class name of the used order base product attribute manager implementation |
||
341 | * |
||
342 | * Each default order base product attribute manager can be replaced by an alternative imlementation. |
||
343 | * To use this implementation, you have to set the last part of the class |
||
344 | * name as configuration value so the manager factory knows which class it |
||
345 | * has to instantiate. |
||
346 | * |
||
347 | * For example, if the name of the default class is |
||
348 | * |
||
349 | * \Aimeos\MShop\Order\Manager\Base\Product\Attribute\Standard |
||
350 | * |
||
351 | * and you want to replace it with your own version named |
||
352 | * |
||
353 | * \Aimeos\MShop\Order\Manager\Base\Product\Attribute\Myattribute |
||
354 | * |
||
355 | * then you have to set the this configuration option: |
||
356 | * |
||
357 | * mshop/order/manager/base/product/attribute/name = Myattribute |
||
358 | * |
||
359 | * The value is the last part of your own class name and it's case sensitive, |
||
360 | * so take care that the configuration value is exactly named like the last |
||
361 | * part of the class name. |
||
362 | * |
||
363 | * The allowed characters of the class name are A-Z, a-z and 0-9. No other |
||
364 | * characters are possible! You should always start the last part of the class |
||
365 | * name with an upper case character and continue only with lower case characters |
||
366 | * or numbers. Avoid chamel case names like "MyAttribute"! |
||
367 | * |
||
368 | * @param string Last part of the class name |
||
369 | * @since 2014.03 |
||
370 | * @category Developer |
||
371 | */ |
||
372 | |||
373 | /** mshop/order/manager/base/product/attribute/decorators/excludes |
||
374 | * Excludes decorators added by the "common" option from the order base product attribute manager |
||
375 | * |
||
376 | * Decorators extend the functionality of a class by adding new aspects |
||
377 | * (e.g. log what is currently done), executing the methods of the underlying |
||
378 | * class only in certain conditions (e.g. only for logged in users) or |
||
379 | * modify what is returned to the caller. |
||
380 | * |
||
381 | * This option allows you to remove a decorator added via |
||
382 | * "mshop/common/manager/decorators/default" before they are wrapped |
||
383 | * around the order base product attribute manager. |
||
384 | * |
||
385 | * mshop/order/manager/base/product/attribute/decorators/excludes = array( 'decorator1' ) |
||
386 | * |
||
387 | * This would remove the decorator named "decorator1" from the list of |
||
388 | * common decorators ("\Aimeos\MShop\Common\Manager\Decorator\*") added via |
||
389 | * "mshop/common/manager/decorators/default" for the order base product attribute manager. |
||
390 | * |
||
391 | * @param array List of decorator names |
||
392 | * @since 2014.03 |
||
393 | * @category Developer |
||
394 | * @see mshop/common/manager/decorators/default |
||
395 | * @see mshop/order/manager/base/product/attribute/decorators/global |
||
396 | * @see mshop/order/manager/base/product/attribute/decorators/local |
||
397 | */ |
||
398 | |||
399 | /** mshop/order/manager/base/product/attribute/decorators/global |
||
400 | * Adds a list of globally available decorators only to the order base product attribute manager |
||
401 | * |
||
402 | * Decorators extend the functionality of a class by adding new aspects |
||
403 | * (e.g. log what is currently done), executing the methods of the underlying |
||
404 | * class only in certain conditions (e.g. only for logged in users) or |
||
405 | * modify what is returned to the caller. |
||
406 | * |
||
407 | * This option allows you to wrap global decorators |
||
408 | * ("\Aimeos\MShop\Common\Manager\Decorator\*") around the order base |
||
409 | * product attribute manager. |
||
410 | * |
||
411 | * mshop/order/manager/base/product/attribute/decorators/global = array( 'decorator1' ) |
||
412 | * |
||
413 | * This would add the decorator named "decorator1" defined by |
||
414 | * "\Aimeos\MShop\Common\Manager\Decorator\Decorator1" only to the order |
||
415 | * base product attribute manager. |
||
416 | * |
||
417 | * @param array List of decorator names |
||
418 | * @since 2014.03 |
||
419 | * @category Developer |
||
420 | * @see mshop/common/manager/decorators/default |
||
421 | * @see mshop/order/manager/base/product/attribute/decorators/excludes |
||
422 | * @see mshop/order/manager/base/product/attribute/decorators/local |
||
423 | */ |
||
424 | |||
425 | /** mshop/order/manager/base/product/attribute/decorators/local |
||
426 | * Adds a list of local decorators only to the order base product attribute manager |
||
427 | * |
||
428 | * Decorators extend the functionality of a class by adding new aspects |
||
429 | * (e.g. log what is currently done), executing the methods of the underlying |
||
430 | * class only in certain conditions (e.g. only for logged in users) or |
||
431 | * modify what is returned to the caller. |
||
432 | * |
||
433 | * This option allows you to wrap local decorators |
||
434 | * ("\Aimeos\MShop\Order\Manager\Base\Product\Attribute\Decorator\*") |
||
435 | * around the order base product attribute manager. |
||
436 | * |
||
437 | * mshop/order/manager/base/product/attribute/decorators/local = array( 'decorator2' ) |
||
438 | * |
||
439 | * This would add the decorator named "decorator2" defined by |
||
440 | * "\Aimeos\MShop\Order\Manager\Base\Product\Attribute\Decorator\Decorator2" |
||
441 | * only to the order base product attribute manager. |
||
442 | * |
||
443 | * @param array List of decorator names |
||
444 | * @since 2014.03 |
||
445 | * @category Developer |
||
446 | * @see mshop/common/manager/decorators/default |
||
447 | * @see mshop/order/manager/base/product/attribute/decorators/excludes |
||
448 | * @see mshop/order/manager/base/product/attribute/decorators/global |
||
449 | */ |
||
450 | |||
451 | return $this->getSubManagerBase( 'order', 'base/product/attribute/' . $manager, $name ); |
||
452 | } |
||
453 | |||
454 | |||
455 | /** |
||
456 | * Adds a new item to the storage or updates an existing one. |
||
457 | * |
||
458 | * @param \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface $item New item that should |
||
459 | * be saved to the storage |
||
460 | * @param boolean $fetch True if the new ID should be returned in the item |
||
461 | * @return \Aimeos\MShop\Common\Item\Iface $item Updated item including the generated ID |
||
462 | */ |
||
463 | public function saveItem( \Aimeos\MShop\Common\Item\Iface $item, $fetch = true ) |
||
464 | { |
||
465 | self::checkClass( '\\Aimeos\\MShop\\Order\\Item\\Base\\Product\\Attribute\\Iface', $item ); |
||
466 | |||
467 | if( !$item->isModified() ) { |
||
468 | return $item; |
||
469 | } |
||
470 | |||
471 | $context = $this->getContext(); |
||
472 | |||
473 | $dbm = $context->getDatabaseManager(); |
||
474 | $dbname = $this->getResourceName(); |
||
475 | $conn = $dbm->acquire( $dbname ); |
||
476 | |||
477 | try |
||
478 | { |
||
479 | $id = $item->getId(); |
||
480 | $date = date( 'Y-m-d H:i:s' ); |
||
481 | |||
482 | if( $id === null ) |
||
483 | { |
||
484 | /** mshop/order/manager/base/product/attribute/standard/insert/mysql |
||
485 | * Inserts a new order record into the database table |
||
486 | * |
||
487 | * @see mshop/order/manager/base/product/attribute/standard/insert/ansi |
||
488 | */ |
||
489 | |||
490 | /** mshop/order/manager/base/product/attribute/standard/insert/ansi |
||
491 | * Inserts a new order record into the database table |
||
492 | * |
||
493 | * Items with no ID yet (i.e. the ID is NULL) will be created in |
||
494 | * the database and the newly created ID retrieved afterwards |
||
495 | * using the "newid" SQL statement. |
||
496 | * |
||
497 | * The SQL statement must be a string suitable for being used as |
||
498 | * prepared statement. It must include question marks for binding |
||
499 | * the values from the order item to the statement before they are |
||
500 | * sent to the database server. The number of question marks must |
||
501 | * be the same as the number of columns listed in the INSERT |
||
502 | * statement. The order of the columns must correspond to the |
||
503 | * order in the saveItems() method, so the correct values are |
||
504 | * bound to the columns. |
||
505 | * |
||
506 | * The SQL statement should conform to the ANSI standard to be |
||
507 | * compatible with most relational database systems. This also |
||
508 | * includes using double quotes for table and column names. |
||
509 | * |
||
510 | * @param string SQL statement for inserting records |
||
511 | * @since 2014.03 |
||
512 | * @category Developer |
||
513 | * @see mshop/order/manager/base/product/attribute/standard/update/ansi |
||
514 | * @see mshop/order/manager/base/product/attribute/standard/newid/ansi |
||
515 | * @see mshop/order/manager/base/product/attribute/standard/delete/ansi |
||
516 | * @see mshop/order/manager/base/product/attribute/standard/search/ansi |
||
517 | * @see mshop/order/manager/base/product/attribute/standard/count/ansi |
||
518 | */ |
||
519 | $path = 'mshop/order/manager/base/product/attribute/standard/insert'; |
||
520 | } |
||
521 | else |
||
522 | { |
||
523 | /** mshop/order/manager/base/product/attribute/standard/update/mysql |
||
524 | * Updates an existing order record in the database |
||
525 | * |
||
526 | * @see mshop/order/manager/base/product/attribute/standard/update/ansi |
||
527 | */ |
||
528 | |||
529 | /** mshop/order/manager/base/product/attribute/standard/update/ansi |
||
530 | * Updates an existing order record in the database |
||
531 | * |
||
532 | * Items which already have an ID (i.e. the ID is not NULL) will |
||
533 | * be updated in the database. |
||
534 | * |
||
535 | * The SQL statement must be a string suitable for being used as |
||
536 | * prepared statement. It must include question marks for binding |
||
537 | * the values from the order item to the statement before they are |
||
538 | * sent to the database server. The order of the columns must |
||
539 | * correspond to the order in the saveItems() method, so the |
||
540 | * correct values are bound to the columns. |
||
541 | * |
||
542 | * The SQL statement should conform to the ANSI standard to be |
||
543 | * compatible with most relational database systems. This also |
||
544 | * includes using double quotes for table and column names. |
||
545 | * |
||
546 | * @param string SQL statement for updating records |
||
547 | * @since 2014.03 |
||
548 | * @category Developer |
||
549 | * @see mshop/order/manager/base/product/attribute/standard/insert/ansi |
||
550 | * @see mshop/order/manager/base/product/attribute/standard/newid/ansi |
||
551 | * @see mshop/order/manager/base/product/attribute/standard/delete/ansi |
||
552 | * @see mshop/order/manager/base/product/attribute/standard/search/ansi |
||
553 | * @see mshop/order/manager/base/product/attribute/standard/count/ansi |
||
554 | */ |
||
555 | $path = 'mshop/order/manager/base/product/attribute/standard/update'; |
||
556 | } |
||
557 | |||
558 | $stmt = $this->getCachedStatement( $conn, $path ); |
||
559 | |||
560 | $stmt->bind( 1, $item->getAttributeId() ); |
||
561 | $stmt->bind( 2, $item->getParentId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
562 | $stmt->bind( 3, $item->getType() ); |
||
563 | $stmt->bind( 4, $item->getCode() ); |
||
564 | $stmt->bind( 5, json_encode( $item->getValue() ) ); |
||
565 | $stmt->bind( 6, $item->getQuantity(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
566 | $stmt->bind( 7, $item->getName() ); |
||
1 ignored issue
–
show
Bug
introduced
by
Loading history...
|
|||
567 | $stmt->bind( 8, $date ); // mtime |
||
568 | $stmt->bind( 9, $context->getEditor() ); |
||
569 | $stmt->bind( 10, $item->getSiteId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
570 | |||
571 | if( $id !== null ) { |
||
572 | $stmt->bind( 11, $id, \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
573 | $item->setId( $id ); |
||
574 | } else { |
||
575 | $stmt->bind( 11, $date ); // ctime |
||
576 | } |
||
577 | |||
578 | $stmt->execute()->finish(); |
||
579 | |||
580 | if( $id === null && $fetch === true ) |
||
581 | { |
||
582 | /** mshop/order/manager/base/product/attribute/standard/newid/mysql |
||
583 | * Retrieves the ID generated by the database when inserting a new record |
||
584 | * |
||
585 | * @see mshop/order/manager/base/product/attribute/standard/newid/ansi |
||
586 | */ |
||
587 | |||
588 | /** mshop/order/manager/base/product/attribute/standard/newid/ansi |
||
589 | * Retrieves the ID generated by the database when inserting a new record |
||
590 | * |
||
591 | * As soon as a new record is inserted into the database table, |
||
592 | * the database server generates a new and unique identifier for |
||
593 | * that record. This ID can be used for retrieving, updating and |
||
594 | * deleting that specific record from the table again. |
||
595 | * |
||
596 | * For MySQL: |
||
597 | * SELECT LAST_INSERT_ID() |
||
598 | * For PostgreSQL: |
||
599 | * SELECT currval('seq_mord_id') |
||
600 | * For SQL Server: |
||
601 | * SELECT SCOPE_IDENTITY() |
||
602 | * For Oracle: |
||
603 | * SELECT "seq_mord_id".CURRVAL FROM DUAL |
||
604 | * |
||
605 | * There's no way to retrive the new ID by a SQL statements that |
||
606 | * fits for most database servers as they implement their own |
||
607 | * specific way. |
||
608 | * |
||
609 | * @param string SQL statement for retrieving the last inserted record ID |
||
610 | * @since 2014.03 |
||
611 | * @category Developer |
||
612 | * @see mshop/order/manager/base/product/attribute/standard/insert/ansi |
||
613 | * @see mshop/order/manager/base/product/attribute/standard/update/ansi |
||
614 | * @see mshop/order/manager/base/product/attribute/standard/delete/ansi |
||
615 | * @see mshop/order/manager/base/product/attribute/standard/search/ansi |
||
616 | * @see mshop/order/manager/base/product/attribute/standard/count/ansi |
||
617 | */ |
||
618 | $path = 'mshop/order/manager/base/product/attribute/standard/newid'; |
||
619 | $item->setId( $this->newId( $conn, $path ) ); |
||
620 | } |
||
621 | |||
622 | $dbm->release( $conn, $dbname ); |
||
623 | } |
||
624 | catch( \Exception $e ) |
||
625 | { |
||
626 | $dbm->release( $conn, $dbname ); |
||
627 | throw $e; |
||
628 | } |
||
629 | |||
630 | return $item; |
||
631 | } |
||
632 | |||
633 | |||
634 | /** |
||
635 | * Searches for order product attributes based on the given criteria. |
||
636 | * |
||
637 | * @param \Aimeos\MW\Criteria\Iface $search Search criteria object |
||
638 | * @param string[] $ref List of domains to fetch list items and referenced items for |
||
639 | * @param integer|null &$total Number of items that are available in total |
||
640 | * @return array List of products implementing \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface |
||
641 | */ |
||
642 | public function searchItems( \Aimeos\MW\Criteria\Iface $search, array $ref = [], &$total = null ) |
||
643 | { |
||
644 | $context = $this->getContext(); |
||
645 | |||
646 | $dbm = $context->getDatabaseManager(); |
||
647 | $dbname = $this->getResourceName(); |
||
648 | $conn = $dbm->acquire( $dbname ); |
||
649 | |||
650 | $items = []; |
||
651 | |||
652 | try |
||
653 | { |
||
654 | $required = array( 'order.base.product.attribute' ); |
||
655 | |||
656 | $level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL; |
||
657 | $level = $context->getConfig()->get( 'mshop/order/manager/sitemode', $level ); |
||
658 | |||
659 | /** mshop/order/manager/base/product/attribute/standard/search/mysql |
||
660 | * Retrieves the records matched by the given criteria in the database |
||
661 | * |
||
662 | * @see mshop/order/manager/base/product/attribute/standard/search/ansi |
||
663 | */ |
||
664 | |||
665 | /** mshop/order/manager/base/product/attribute/standard/search/ansi |
||
666 | * Retrieves the records matched by the given criteria in the database |
||
667 | * |
||
668 | * Fetches the records matched by the given criteria from the order |
||
669 | * database. The records must be from one of the sites that are |
||
670 | * configured via the context item. If the current site is part of |
||
671 | * a tree of sites, the SELECT statement can retrieve all records |
||
672 | * from the current site and the complete sub-tree of sites. |
||
673 | * |
||
674 | * As the records can normally be limited by criteria from sub-managers, |
||
675 | * their tables must be joined in the SQL context. This is done by |
||
676 | * using the "internaldeps" property from the definition of the ID |
||
677 | * column of the sub-managers. These internal dependencies specify |
||
678 | * the JOIN between the tables and the used columns for joining. The |
||
679 | * ":joins" placeholder is then replaced by the JOIN strings from |
||
680 | * the sub-managers. |
||
681 | * |
||
682 | * To limit the records matched, conditions can be added to the given |
||
683 | * criteria object. It can contain comparisons like column names that |
||
684 | * must match specific values which can be combined by AND, OR or NOT |
||
685 | * operators. The resulting string of SQL conditions replaces the |
||
686 | * ":cond" placeholder before the statement is sent to the database |
||
687 | * server. |
||
688 | * |
||
689 | * If the records that are retrieved should be ordered by one or more |
||
690 | * columns, the generated string of column / sort direction pairs |
||
691 | * replaces the ":order" placeholder. In case no ordering is required, |
||
692 | * the complete ORDER BY part including the "\/*-orderby*\/...\/*orderby-*\/" |
||
693 | * markers is removed to speed up retrieving the records. Columns of |
||
694 | * sub-managers can also be used for ordering the result set but then |
||
695 | * no index can be used. |
||
696 | * |
||
697 | * The number of returned records can be limited and can start at any |
||
698 | * number between the begining and the end of the result set. For that |
||
699 | * the ":size" and ":start" placeholders are replaced by the |
||
700 | * corresponding values from the criteria object. The default values |
||
701 | * are 0 for the start and 100 for the size value. |
||
702 | * |
||
703 | * The SQL statement should conform to the ANSI standard to be |
||
704 | * compatible with most relational database systems. This also |
||
705 | * includes using double quotes for table and column names. |
||
706 | * |
||
707 | * @param string SQL statement for searching items |
||
708 | * @since 2014.03 |
||
709 | * @category Developer |
||
710 | * @see mshop/order/manager/base/product/attribute/standard/insert/ansi |
||
711 | * @see mshop/order/manager/base/product/attribute/standard/update/ansi |
||
712 | * @see mshop/order/manager/base/product/attribute/standard/newid/ansi |
||
713 | * @see mshop/order/manager/base/product/attribute/standard/delete/ansi |
||
714 | * @see mshop/order/manager/base/product/attribute/standard/count/ansi |
||
715 | */ |
||
716 | $cfgPathSearch = 'mshop/order/manager/base/product/attribute/standard/search'; |
||
717 | |||
718 | /** mshop/order/manager/base/product/attribute/standard/count/mysql |
||
719 | * Counts the number of records matched by the given criteria in the database |
||
720 | * |
||
721 | * @see mshop/order/manager/base/product/attribute/standard/count/ansi |
||
722 | */ |
||
723 | |||
724 | /** mshop/order/manager/base/product/attribute/standard/count/ansi |
||
725 | * Counts the number of records matched by the given criteria in the database |
||
726 | * |
||
727 | * Counts all records matched by the given criteria from the order |
||
728 | * database. The records must be from one of the sites that are |
||
729 | * configured via the context item. If the current site is part of |
||
730 | * a tree of sites, the statement can count all records from the |
||
731 | * current site and the complete sub-tree of sites. |
||
732 | * |
||
733 | * As the records can normally be limited by criteria from sub-managers, |
||
734 | * their tables must be joined in the SQL context. This is done by |
||
735 | * using the "internaldeps" property from the definition of the ID |
||
736 | * column of the sub-managers. These internal dependencies specify |
||
737 | * the JOIN between the tables and the used columns for joining. The |
||
738 | * ":joins" placeholder is then replaced by the JOIN strings from |
||
739 | * the sub-managers. |
||
740 | * |
||
741 | * To limit the records matched, conditions can be added to the given |
||
742 | * criteria object. It can contain comparisons like column names that |
||
743 | * must match specific values which can be combined by AND, OR or NOT |
||
744 | * operators. The resulting string of SQL conditions replaces the |
||
745 | * ":cond" placeholder before the statement is sent to the database |
||
746 | * server. |
||
747 | * |
||
748 | * Both, the strings for ":joins" and for ":cond" are the same as for |
||
749 | * the "search" SQL statement. |
||
750 | * |
||
751 | * Contrary to the "search" statement, it doesn't return any records |
||
752 | * but instead the number of records that have been found. As counting |
||
753 | * thousands of records can be a long running task, the maximum number |
||
754 | * of counted records is limited for performance reasons. |
||
755 | * |
||
756 | * The SQL statement should conform to the ANSI standard to be |
||
757 | * compatible with most relational database systems. This also |
||
758 | * includes using double quotes for table and column names. |
||
759 | * |
||
760 | * @param string SQL statement for counting items |
||
761 | * @since 2014.03 |
||
762 | * @category Developer |
||
763 | * @see mshop/order/manager/base/product/attribute/standard/insert/ansi |
||
764 | * @see mshop/order/manager/base/product/attribute/standard/update/ansi |
||
765 | * @see mshop/order/manager/base/product/attribute/standard/newid/ansi |
||
766 | * @see mshop/order/manager/base/product/attribute/standard/delete/ansi |
||
767 | * @see mshop/order/manager/base/product/attribute/standard/search/ansi |
||
768 | */ |
||
769 | $cfgPathCount = 'mshop/order/manager/base/product/attribute/standard/count'; |
||
770 | |||
771 | $results = $this->searchItemsBase( $conn, $search, $cfgPathSearch, $cfgPathCount, |
||
772 | $required, $total, $level ); |
||
773 | |||
774 | try |
||
775 | { |
||
776 | while( ( $row = $results->fetch() ) !== false ) |
||
777 | { |
||
778 | if( ( $value = json_decode( $row['order.base.product.attribute.value'], true ) ) !== null ) { |
||
779 | $row['order.base.product.attribute.value'] = $value; |
||
780 | } |
||
781 | $items[$row['order.base.product.attribute.id']] = $this->createItemBase( $row ); |
||
782 | } |
||
783 | } |
||
784 | catch( \Exception $e ) |
||
785 | { |
||
786 | $results->finish(); |
||
787 | throw $e; |
||
788 | } |
||
789 | |||
790 | $dbm->release( $conn, $dbname ); |
||
791 | } |
||
792 | catch( \Exception $e ) |
||
793 | { |
||
794 | $dbm->release( $conn, $dbname ); |
||
795 | throw $e; |
||
796 | } |
||
797 | |||
798 | return $items; |
||
799 | } |
||
800 | |||
801 | |||
802 | /** |
||
803 | * Creates new order base product attribute item object initialized with given parameters. |
||
804 | * |
||
805 | * @param array $values Associative array of order product attribute values |
||
806 | * @return \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface |
||
807 | */ |
||
808 | protected function createItemBase( array $values = [] ) |
||
809 | { |
||
810 | return new \Aimeos\MShop\Order\Item\Base\Product\Attribute\Standard( $values ); |
||
811 | } |
||
812 | } |
||
813 |