1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
4
|
|
|
* @copyright Aimeos (aimeos.org), 2022-2024 |
5
|
|
|
* @package MShop |
6
|
|
|
* @subpackage Basket |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Basket\Manager; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Default implementation for basket manager. |
14
|
|
|
* |
15
|
|
|
* @package MShop |
16
|
|
|
* @subpackage Basket |
17
|
|
|
*/ |
18
|
|
|
class Standard |
19
|
|
|
extends \Aimeos\MShop\Common\Manager\Base |
20
|
|
|
implements \Aimeos\MShop\Basket\Manager\Iface, \Aimeos\MShop\Common\Manager\Factory\Iface |
21
|
|
|
{ |
22
|
|
|
private array $searchConfig = array( |
23
|
|
|
'basket.id' => array( |
24
|
|
|
'code' => 'basket.id', |
25
|
|
|
'internalcode' => 'mbas."id"', |
26
|
|
|
'label' => 'Basket ID', |
27
|
|
|
'public' => false, |
28
|
|
|
), |
29
|
|
|
'basket.siteid' => array( |
30
|
|
|
'code' => 'basket.siteid', |
31
|
|
|
'internalcode' => 'mbas."siteid"', |
32
|
|
|
'label' => 'Basket site ID', |
33
|
|
|
'public' => false, |
34
|
|
|
), |
35
|
|
|
'basket.customerid' => array( |
36
|
|
|
'code' => 'basket.customerid', |
37
|
|
|
'internalcode' => 'mbas."customerid"', |
38
|
|
|
'label' => 'Basket customer ID', |
39
|
|
|
'public' => false, |
40
|
|
|
), |
41
|
|
|
'basket.name' => array( |
42
|
|
|
'code' => 'basket.name', |
43
|
|
|
'internalcode' => 'mbas."name"', |
44
|
|
|
'label' => 'Basket name', |
45
|
|
|
), |
46
|
|
|
'basket.content' => array( |
47
|
|
|
'code' => 'basket.content', |
48
|
|
|
'internalcode' => 'mbas."content"', |
49
|
|
|
'label' => 'Basket content', |
50
|
|
|
), |
51
|
|
|
'basket.ctime' => array( |
52
|
|
|
'code' => 'basket.ctime', |
53
|
|
|
'internalcode' => 'mbas."ctime"', |
54
|
|
|
'label' => 'Basket create date/time', |
55
|
|
|
'type' => 'datetime', |
56
|
|
|
'public' => false, |
57
|
|
|
), |
58
|
|
|
'basket.mtime' => array( |
59
|
|
|
'code' => 'basket.mtime', |
60
|
|
|
'internalcode' => 'mbas."mtime"', |
61
|
|
|
'label' => 'Basket modify date/time', |
62
|
|
|
'type' => 'datetime', |
63
|
|
|
'public' => false, |
64
|
|
|
), |
65
|
|
|
'basket.editor' => array( |
66
|
|
|
'code' => 'basket.editor', |
67
|
|
|
'internalcode' => 'mbas."editor"', |
68
|
|
|
'label' => 'Basket editor', |
69
|
|
|
'public' => false, |
70
|
|
|
), |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Initializes the object. |
76
|
|
|
* |
77
|
|
|
* @param \Aimeos\MShop\ContextIface $context Context object |
78
|
|
|
*/ |
79
|
|
|
public function __construct( \Aimeos\MShop\ContextIface $context ) |
80
|
|
|
{ |
81
|
|
|
parent::__construct( $context ); |
82
|
|
|
|
83
|
|
|
/** mshop/basket/manager/resource |
84
|
|
|
* Name of the database connection resource to use |
85
|
|
|
* |
86
|
|
|
* You can configure a different database connection for each data domain |
87
|
|
|
* and if no such connection name exists, the "db" connection will be used. |
88
|
|
|
* It's also possible to use the same database connection for different |
89
|
|
|
* data domains by configuring the same connection name using this setting. |
90
|
|
|
* |
91
|
|
|
* @param string Database connection name |
92
|
|
|
* @since 2023.04 |
93
|
|
|
*/ |
94
|
|
|
$this->setResourceName( $context->config()->get( 'mshop/basket/manager/resource', 'db-basket' ) ); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Removes old entries from the storage. |
100
|
|
|
* |
101
|
|
|
* @param iterable $siteids List of IDs for sites whose entries should be deleted |
102
|
|
|
* @return \Aimeos\MShop\Order\Manager\Basket\Iface Manager object for chaining method calls |
|
|
|
|
103
|
|
|
*/ |
104
|
|
|
public function clear( iterable $siteids ) : \Aimeos\MShop\Common\Manager\Iface |
105
|
|
|
{ |
106
|
|
|
$path = 'mshop/basket/manager/submanagers'; |
107
|
|
|
foreach( $this->context()->config()->get( $path, [] ) as $domain ) { |
108
|
|
|
$this->object()->getSubManager( $domain )->clear( $siteids ); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
return $this->clearBase( $siteids, 'mshop/basket/manager/delete' ); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Creates a new empty item instance |
117
|
|
|
* |
118
|
|
|
* @param array $values Values the item should be initialized with |
119
|
|
|
* @return \Aimeos\MShop\Basket\Item\Iface New basket item object |
120
|
|
|
*/ |
121
|
|
|
public function create( array $values = [] ) : \Aimeos\MShop\Common\Item\Iface |
122
|
|
|
{ |
123
|
|
|
$values['basket.siteid'] = $values['basket.siteid'] ?? $this->context()->locale()->getSiteId(); |
124
|
|
|
return $this->createItemBase( $values ); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Creates a search critera object |
130
|
|
|
* |
131
|
|
|
* @param bool|null $default Add default criteria or NULL for relaxed default criteria |
132
|
|
|
* @param bool $site TRUE for adding site criteria to limit items by the site of related items |
133
|
|
|
* @return \Aimeos\Base\Criteria\Iface New search criteria object |
134
|
|
|
*/ |
135
|
|
|
public function filter( ?bool $default = false, bool $site = false ) : \Aimeos\Base\Criteria\Iface |
136
|
|
|
{ |
137
|
|
|
$filter = parent::filter( $default, $site ); |
138
|
|
|
|
139
|
|
|
if( $default !== false ) { |
140
|
|
|
$filter->add( 'basket.customerid', '==', $this->context()->user() ); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
return $filter; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Adds or updates an basket object. |
149
|
|
|
* |
150
|
|
|
* @param \Aimeos\MShop\Basket\Item\Iface $item Order basket object whose data should be saved |
151
|
|
|
* @param bool $fetch True if the new ID should be returned in the item |
152
|
|
|
* @return \Aimeos\MShop\Basket\Item\Iface $item Updated item including the generated ID |
153
|
|
|
*/ |
154
|
|
|
protected function saveItem( \Aimeos\MShop\Basket\Item\Iface $item, bool $fetch = true ) : \Aimeos\MShop\Basket\Item\Iface |
155
|
|
|
{ |
156
|
|
|
if( !$item->isModified() ) { |
157
|
|
|
return $item; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
$context = $this->context(); |
161
|
|
|
$date = $context->datetime(); |
162
|
|
|
$conn = $context->db( $this->getResourceName() ); |
163
|
|
|
$columns = $this->object()->getSaveAttributes(); |
164
|
|
|
|
165
|
|
|
/** mshop/basket/manager/insert/mysql |
166
|
|
|
* Inserts a new basket record into the database table or updates an existing one |
167
|
|
|
* |
168
|
|
|
* The SQL statement must be a string suitable for being used as |
169
|
|
|
* prepared statement. It must include question marks for binding |
170
|
|
|
* the values from the basket item to the statement before they are |
171
|
|
|
* sent to the database server. The number of question marks must |
172
|
|
|
* be the same as the number of columns listed in the INSERT |
173
|
|
|
* statement. The order of the columns must correspond to the |
174
|
|
|
* order in the save() method, so the correct values are |
175
|
|
|
* bound to the columns. |
176
|
|
|
* |
177
|
|
|
* The SQL statement should conform to the ANSI standard to be |
178
|
|
|
* compatible with most relational database systems. This also |
179
|
|
|
* includes using double quotes for table and column names. |
180
|
|
|
* |
181
|
|
|
* @param string SQL statement for inserting or updating records |
182
|
|
|
* @since 2022.10 |
183
|
|
|
* @see mshop/basket/manager/newid/ansi |
184
|
|
|
* @see mshop/basket/manager/delete/ansi |
185
|
|
|
* @see mshop/basket/manager/search/ansi |
186
|
|
|
* @see mshop/basket/manager/count/ansi |
187
|
|
|
*/ |
188
|
|
|
$path = 'mshop/basket/manager/insert'; |
189
|
|
|
|
190
|
|
|
$sql = $this->addSqlColumns( array_keys( $columns ), $this->getSqlConfig( $path ) ); |
|
|
|
|
191
|
|
|
$stmt = $this->getCachedStatement( $conn, $path, $sql ); |
192
|
|
|
|
193
|
|
|
$serialized = base64_encode( serialize( clone $item->getItem() ) ); |
194
|
|
|
$idx = 1; |
195
|
|
|
|
196
|
|
|
foreach( $columns as $name => $entry ) { |
197
|
|
|
$stmt->bind( $idx++, $item->get( $name ), \Aimeos\Base\Criteria\SQL::type( $entry->getType() ) ); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
// insert |
201
|
|
|
$stmt->bind( $idx++, $item->getCustomerId() ); |
202
|
|
|
$stmt->bind( $idx++, $serialized ); |
203
|
|
|
$stmt->bind( $idx++, $item->getName() ); |
204
|
|
|
$stmt->bind( $idx++, $date ); //mtime |
205
|
|
|
$stmt->bind( $idx++, $context->editor() ); |
206
|
|
|
$stmt->bind( $idx++, $this->siteId( $item->getSiteId(), \Aimeos\MShop\Locale\Manager\Base::SITE_SUBTREE ) ); |
207
|
|
|
$stmt->bind( $idx++, $date ); //ctime |
208
|
|
|
$stmt->bind( $idx++, $item->getId() ); |
209
|
|
|
// update |
210
|
|
|
$stmt->bind( $idx++, $item->getCustomerId() ); |
211
|
|
|
$stmt->bind( $idx++, $serialized ); |
212
|
|
|
$stmt->bind( $idx++, $item->getName() ); |
213
|
|
|
$stmt->bind( $idx++, $date ); //mtime |
214
|
|
|
$stmt->bind( $idx++, $context->editor() ); |
215
|
|
|
|
216
|
|
|
$stmt->execute()->finish(); |
217
|
|
|
|
218
|
|
|
return $item; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Returns the basket item specified by its ID. |
224
|
|
|
* |
225
|
|
|
* @param string $id Unique ID of the basket item |
226
|
|
|
* @param string[] $ref List of domains to fetch list items and referenced items for |
227
|
|
|
* @param bool|null $default Add default criteria or NULL for relaxed default criteria |
228
|
|
|
* @return \Aimeos\MShop\Basket\Item\Iface Returns basket item of the given id |
229
|
|
|
* @throws \Aimeos\MShop\Order\Exception If item couldn't be found |
230
|
|
|
*/ |
231
|
|
|
public function get( string $id, array $ref = [], ?bool $default = false ) : \Aimeos\MShop\Common\Item\Iface |
232
|
|
|
{ |
233
|
|
|
return $this->getItemBase( 'basket.id', $id, $ref, $default ); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Removes multiple items. |
239
|
|
|
* |
240
|
|
|
* @param \Aimeos\MShop\Common\Item\Iface[]|string[] $itemIds List of item objects or IDs of the items |
241
|
|
|
* @return \Aimeos\MShop\Order\Manager\Basket\Iface Manager object for chaining method calls |
242
|
|
|
*/ |
243
|
|
|
public function delete( $itemIds ) : \Aimeos\MShop\Common\Manager\Iface |
244
|
|
|
{ |
245
|
|
|
/** mshop/basket/manager/delete/mysql |
246
|
|
|
* Deletes the items matched by the given IDs from the database |
247
|
|
|
* |
248
|
|
|
* @see mshop/basket/manager/delete/ansi |
249
|
|
|
*/ |
250
|
|
|
|
251
|
|
|
/** mshop/basket/manager/delete/ansi |
252
|
|
|
* Deletes the items matched by the given IDs from the database |
253
|
|
|
* |
254
|
|
|
* Removes the records specified by the given IDs from the basket database. |
255
|
|
|
* The records must be from the site that is configured via the |
256
|
|
|
* context item. |
257
|
|
|
* |
258
|
|
|
* The ":cond" placeholder is replaced by the name of the ID column and |
259
|
|
|
* the given ID or list of IDs while the site ID is bound to the question |
260
|
|
|
* mark. |
261
|
|
|
* |
262
|
|
|
* The SQL statement should conform to the ANSI standard to be |
263
|
|
|
* compatible with most relational database systems. This also |
264
|
|
|
* includes using double quotes for table and column names. |
265
|
|
|
* |
266
|
|
|
* @param string SQL statement for deleting items |
267
|
|
|
* @since 2022.10 |
268
|
|
|
* @see mshop/basket/manager/insert/ansi |
269
|
|
|
* @see mshop/basket/manager/update/ansi |
270
|
|
|
* @see mshop/basket/manager/newid/ansi |
271
|
|
|
* @see mshop/basket/manager/search/ansi |
272
|
|
|
* @see mshop/basket/manager/count/ansi |
273
|
|
|
*/ |
274
|
|
|
$path = 'mshop/basket/manager/delete'; |
275
|
|
|
|
276
|
|
|
return $this->deleteItemsBase( $itemIds, $path ); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Returns the attributes that can be used for searching. |
282
|
|
|
* |
283
|
|
|
* @param bool $withsub Return also attributes of sub-managers if true |
284
|
|
|
* @return \Aimeos\Base\Criteria\Attribute\Iface[] List of search attribute items |
285
|
|
|
*/ |
286
|
|
|
public function getSearchAttributes( bool $withsub = true ) : array |
287
|
|
|
{ |
288
|
|
|
/** mshop/basket/manager/submanagers |
289
|
|
|
* List of manager names that can be instantiated by the basket manager |
290
|
|
|
* |
291
|
|
|
* Managers provide a generic interface to the underlying storage. |
292
|
|
|
* Each manager has or can have sub-managers caring about particular |
293
|
|
|
* aspects. Each of these sub-managers can be instantiated by its |
294
|
|
|
* parent manager using the getSubManager() method. |
295
|
|
|
* |
296
|
|
|
* The search keys from sub-managers can be normally used in the |
297
|
|
|
* manager as well. It allows you to search for items of the manager |
298
|
|
|
* using the search keys of the sub-managers to further limit the |
299
|
|
|
* retrieved list of items. |
300
|
|
|
* |
301
|
|
|
* @param array List of sub-manager names |
302
|
|
|
* @since 2022.10 |
303
|
|
|
*/ |
304
|
|
|
$path = 'mshop/basket/manager/submanagers'; |
305
|
|
|
|
306
|
|
|
return $this->getSearchAttributesBase( $this->searchConfig, $path, [], $withsub ); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* Returns a new manager for basket extensions. |
312
|
|
|
* |
313
|
|
|
* @param string $manager Name of the sub manager type in lower case |
314
|
|
|
* @param string|null $name Name of the implementation, will be from configuration (or Default) if null |
315
|
|
|
* @return \Aimeos\MShop\Common\Manager\Iface Manager extending the domain functionality |
316
|
|
|
*/ |
317
|
|
|
public function getSubManager( string $manager, ?string $name = null ) : \Aimeos\MShop\Common\Manager\Iface |
318
|
|
|
{ |
319
|
|
|
/** mshop/basket/manager/name |
320
|
|
|
* Class name of the used basket manager implementation |
321
|
|
|
* |
322
|
|
|
* Each default basket manager can be replaced by an alternative imlementation. |
323
|
|
|
* To use this implementation, you have to set the last part of the class |
324
|
|
|
* name as configuration value so the manager factory knows which class it |
325
|
|
|
* has to instantiate. |
326
|
|
|
* |
327
|
|
|
* For example, if the name of the default class is |
328
|
|
|
* |
329
|
|
|
* \Aimeos\MShop\Order\Manager\Basket\Standard |
330
|
|
|
* |
331
|
|
|
* and you want to replace it with your own version named |
332
|
|
|
* |
333
|
|
|
* \Aimeos\MShop\Order\Manager\Basket\Mybasket |
334
|
|
|
* |
335
|
|
|
* then you have to set the this configuration option: |
336
|
|
|
* |
337
|
|
|
* mshop/basket/manager/name = Mybasket |
338
|
|
|
* |
339
|
|
|
* The value is the last part of your own class name and it's case sensitive, |
340
|
|
|
* so take care that the configuration value is exactly named like the last |
341
|
|
|
* part of the class name. |
342
|
|
|
* |
343
|
|
|
* The allowed characters of the class name are A-Z, a-z and 0-9. No other |
344
|
|
|
* characters are possible! You should always start the last part of the class |
345
|
|
|
* name with an upper case character and continue only with lower case characters |
346
|
|
|
* or numbers. Avoid chamel case names like "MyBasket"! |
347
|
|
|
* |
348
|
|
|
* @param string Last part of the class name |
349
|
|
|
* @since 2022.10 |
350
|
|
|
*/ |
351
|
|
|
|
352
|
|
|
/** mshop/basket/manager/decorators/excludes |
353
|
|
|
* Excludes decorators added by the "common" option from the basket manager |
354
|
|
|
* |
355
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
356
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
357
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
358
|
|
|
* modify what is returned to the caller. |
359
|
|
|
* |
360
|
|
|
* This option allows you to remove a decorator added via |
361
|
|
|
* "mshop/common/manager/decorators/default" before they are wrapped |
362
|
|
|
* around the basket manager. |
363
|
|
|
* |
364
|
|
|
* mshop/basket/manager/decorators/excludes = array( 'decorator1' ) |
365
|
|
|
* |
366
|
|
|
* This would remove the decorator named "decorator1" from the list of |
367
|
|
|
* common decorators ("\Aimeos\MShop\Common\Manager\Decorator\*") added via |
368
|
|
|
* "mshop/common/manager/decorators/default" for the basket manager. |
369
|
|
|
* |
370
|
|
|
* @param array List of decorator names |
371
|
|
|
* @since 2022.10 |
372
|
|
|
* @see mshop/common/manager/decorators/default |
373
|
|
|
* @see mshop/basket/manager/decorators/global |
374
|
|
|
* @see mshop/basket/manager/decorators/local |
375
|
|
|
*/ |
376
|
|
|
|
377
|
|
|
/** mshop/basket/manager/decorators/global |
378
|
|
|
* Adds a list of globally available decorators only to the basket manager |
379
|
|
|
* |
380
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
381
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
382
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
383
|
|
|
* modify what is returned to the caller. |
384
|
|
|
* |
385
|
|
|
* This option allows you to wrap global decorators |
386
|
|
|
* ("\Aimeos\MShop\Common\Manager\Decorator\*") around the basket |
387
|
|
|
* manager. |
388
|
|
|
* |
389
|
|
|
* mshop/basket/manager/decorators/global = array( 'decorator1' ) |
390
|
|
|
* |
391
|
|
|
* This would add the decorator named "decorator1" defined by |
392
|
|
|
* "\Aimeos\MShop\Common\Manager\Decorator\Decorator1" only to the |
393
|
|
|
* basket manager. |
394
|
|
|
* |
395
|
|
|
* @param array List of decorator names |
396
|
|
|
* @since 2022.10 |
397
|
|
|
* @see mshop/common/manager/decorators/default |
398
|
|
|
* @see mshop/basket/manager/decorators/excludes |
399
|
|
|
* @see mshop/basket/manager/decorators/local |
400
|
|
|
*/ |
401
|
|
|
|
402
|
|
|
/** mshop/basket/manager/decorators/local |
403
|
|
|
* Adds a list of local decorators only to the basket manager |
404
|
|
|
* |
405
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
406
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
407
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
408
|
|
|
* modify what is returned to the caller. |
409
|
|
|
* |
410
|
|
|
* This option allows you to wrap local decorators |
411
|
|
|
* ("\Aimeos\MShop\Order\Manager\Basket\Decorator\*") around the |
412
|
|
|
* basket manager. |
413
|
|
|
* |
414
|
|
|
* mshop/basket/manager/decorators/local = array( 'decorator2' ) |
415
|
|
|
* |
416
|
|
|
* This would add the decorator named "decorator2" defined by |
417
|
|
|
* "\Aimeos\MShop\Order\Manager\Basket\Decorator\Decorator2" only to the |
418
|
|
|
* basket manager. |
419
|
|
|
* |
420
|
|
|
* @param array List of decorator names |
421
|
|
|
* @since 2022.10 |
422
|
|
|
* @see mshop/common/manager/decorators/default |
423
|
|
|
* @see mshop/basket/manager/decorators/excludes |
424
|
|
|
* @see mshop/basket/manager/decorators/global |
425
|
|
|
*/ |
426
|
|
|
|
427
|
|
|
return $this->getSubManagerBase( 'basket', $manager, $name ); |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
|
431
|
|
|
/** |
432
|
|
|
* Searches for all items matching the given critera. |
433
|
|
|
* |
434
|
|
|
* @param \Aimeos\Base\Criteria\Iface $search Search criteria object |
435
|
|
|
* @param string[] $ref List of domains to fetch list items and referenced items for |
436
|
|
|
* @param int|null &$total Number of items that are available in total |
437
|
|
|
* @return \Aimeos\Map List of items implementing \Aimeos\MShop\Basket\Item\Iface with ids as keys |
438
|
|
|
*/ |
439
|
|
|
public function search( \Aimeos\Base\Criteria\Iface $search, array $ref = [], ?int &$total = null ) : \Aimeos\Map |
440
|
|
|
{ |
441
|
|
|
$items = []; |
442
|
|
|
$context = $this->context(); |
443
|
|
|
$conn = $context->db( $this->getResourceName() ); |
444
|
|
|
|
445
|
|
|
$required = array( 'basket' ); |
446
|
|
|
|
447
|
|
|
$level = \Aimeos\MShop\Locale\Manager\Base::SITE_SUBTREE; |
448
|
|
|
$level = $context->config()->get( 'mshop/basket/manager/sitemode', $level ); |
449
|
|
|
|
450
|
|
|
/** mshop/basket/manager/search/mysql |
451
|
|
|
* Retrieves the records matched by the given criteria in the database |
452
|
|
|
* |
453
|
|
|
* @see mshop/basket/manager/search/ansi |
454
|
|
|
*/ |
455
|
|
|
|
456
|
|
|
/** mshop/basket/manager/search/ansi |
457
|
|
|
* Retrieves the records matched by the given criteria in the database |
458
|
|
|
* |
459
|
|
|
* Fetches the records matched by the given criteria from the basket |
460
|
|
|
* database. The records must be from one of the sites that are |
461
|
|
|
* configured via the context item. If the current site is part of |
462
|
|
|
* a tree of sites, the SELECT statement can retrieve all records |
463
|
|
|
* from the current site and the complete sub-tree of sites. |
464
|
|
|
* |
465
|
|
|
* As the records can normally be limited by criteria from sub-managers, |
466
|
|
|
* their tables must be joined in the SQL context. This is done by |
467
|
|
|
* using the "internaldeps" property from the definition of the ID |
468
|
|
|
* column of the sub-managers. These internal dependencies specify |
469
|
|
|
* the JOIN between the tables and the used columns for joining. The |
470
|
|
|
* ":joins" placeholder is then replaced by the JOIN strings from |
471
|
|
|
* the sub-managers. |
472
|
|
|
* |
473
|
|
|
* To limit the records matched, conditions can be added to the given |
474
|
|
|
* criteria object. It can contain comparisons like column names that |
475
|
|
|
* must match specific values which can be combined by AND, OR or NOT |
476
|
|
|
* operators. The resulting string of SQL conditions replaces the |
477
|
|
|
* ":cond" placeholder before the statement is sent to the database |
478
|
|
|
* server. |
479
|
|
|
* |
480
|
|
|
* If the records that are retrieved should be ordered by one or more |
481
|
|
|
* columns, the generated string of column / sort direction pairs |
482
|
|
|
* replaces the ":order" placeholder. Columns of |
483
|
|
|
* sub-managers can also be used for ordering the result set but then |
484
|
|
|
* no index can be used. |
485
|
|
|
* |
486
|
|
|
* The number of returned records can be limited and can start at any |
487
|
|
|
* number between the begining and the end of the result set. For that |
488
|
|
|
* the ":size" and ":start" placeholders are replaced by the |
489
|
|
|
* corresponding values from the criteria object. The default values |
490
|
|
|
* are 0 for the start and 100 for the size value. |
491
|
|
|
* |
492
|
|
|
* The SQL statement should conform to the ANSI standard to be |
493
|
|
|
* compatible with most relational database systems. This also |
494
|
|
|
* includes using double quotes for table and column names. |
495
|
|
|
* |
496
|
|
|
* @param string SQL statement for searching items |
497
|
|
|
* @since 2022.10 |
498
|
|
|
* @see mshop/basket/manager/insert/ansi |
499
|
|
|
* @see mshop/basket/manager/update/ansi |
500
|
|
|
* @see mshop/basket/manager/newid/ansi |
501
|
|
|
* @see mshop/basket/manager/delete/ansi |
502
|
|
|
* @see mshop/basket/manager/count/ansi |
503
|
|
|
*/ |
504
|
|
|
$cfgPathSearch = 'mshop/basket/manager/search'; |
505
|
|
|
|
506
|
|
|
/** mshop/basket/manager/count/mysql |
507
|
|
|
* Counts the number of records matched by the given criteria in the database |
508
|
|
|
* |
509
|
|
|
* @see mshop/basket/manager/count/ansi |
510
|
|
|
*/ |
511
|
|
|
|
512
|
|
|
/** mshop/basket/manager/count/ansi |
513
|
|
|
* Counts the number of records matched by the given criteria in the database |
514
|
|
|
* |
515
|
|
|
* Counts all records matched by the given criteria from the basket |
516
|
|
|
* database. The records must be from one of the sites that are |
517
|
|
|
* configured via the context item. If the current site is part of |
518
|
|
|
* a tree of sites, the statement can count all records from the |
519
|
|
|
* current site and the complete sub-tree of sites. |
520
|
|
|
* |
521
|
|
|
* As the records can normally be limited by criteria from sub-managers, |
522
|
|
|
* their tables must be joined in the SQL context. This is done by |
523
|
|
|
* using the "internaldeps" property from the definition of the ID |
524
|
|
|
* column of the sub-managers. These internal dependencies specify |
525
|
|
|
* the JOIN between the tables and the used columns for joining. The |
526
|
|
|
* ":joins" placeholder is then replaced by the JOIN strings from |
527
|
|
|
* the sub-managers. |
528
|
|
|
* |
529
|
|
|
* To limit the records matched, conditions can be added to the given |
530
|
|
|
* criteria object. It can contain comparisons like column names that |
531
|
|
|
* must match specific values which can be combined by AND, OR or NOT |
532
|
|
|
* operators. The resulting string of SQL conditions replaces the |
533
|
|
|
* ":cond" placeholder before the statement is sent to the database |
534
|
|
|
* server. |
535
|
|
|
* |
536
|
|
|
* Both, the strings for ":joins" and for ":cond" are the same as for |
537
|
|
|
* the "search" SQL statement. |
538
|
|
|
* |
539
|
|
|
* Contrary to the "search" statement, it doesn't return any records |
540
|
|
|
* but instead the number of records that have been found. As counting |
541
|
|
|
* thousands of records can be a long running task, the maximum number |
542
|
|
|
* of counted records is limited for performance reasons. |
543
|
|
|
* |
544
|
|
|
* The SQL statement should conform to the ANSI standard to be |
545
|
|
|
* compatible with most relational database systems. This also |
546
|
|
|
* includes using double quotes for table and column names. |
547
|
|
|
* |
548
|
|
|
* @param string SQL statement for counting items |
549
|
|
|
* @since 2022.10 |
550
|
|
|
* @see mshop/basket/manager/insert/ansi |
551
|
|
|
* @see mshop/basket/manager/update/ansi |
552
|
|
|
* @see mshop/basket/manager/newid/ansi |
553
|
|
|
* @see mshop/basket/manager/delete/ansi |
554
|
|
|
* @see mshop/basket/manager/search/ansi |
555
|
|
|
*/ |
556
|
|
|
$cfgPathCount = 'mshop/basket/manager/count'; |
557
|
|
|
|
558
|
|
|
$results = $this->searchItemsBase( $conn, $search, $cfgPathSearch, $cfgPathCount, $required, $total, $level ); |
559
|
|
|
|
560
|
|
|
while( $row = $results->fetch() ) |
561
|
|
|
{ |
562
|
|
|
$basket = unserialize( base64_decode( $row['basket.content'] ) ); |
563
|
|
|
|
564
|
|
|
if( !( $basket instanceof \Aimeos\MShop\Order\Item\Iface ) ) |
565
|
|
|
{ |
566
|
|
|
$msg = sprintf( 'Invalid serialized basket. "%1$s" returned "%2$s".', __METHOD__, $row['basket.content'] ); |
567
|
|
|
$context->logger()->warning( $msg, 'core/basket' ); |
568
|
|
|
} |
569
|
|
|
|
570
|
|
|
if( $item = $this->createItemBase( $row, $basket ?: null ) ) { |
571
|
|
|
$items[$row['basket.id']] = $item; |
572
|
|
|
} |
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
return map( $items ); |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
|
579
|
|
|
/** |
580
|
|
|
* Creates a new basket object. |
581
|
|
|
* |
582
|
|
|
* @param array $values List of attributes for the basket object |
583
|
|
|
* @param \Aimeos\MShop\Order\Item\Iface|null $basket Basket object |
584
|
|
|
* @return \Aimeos\MShop\Basket\Item\Iface New basket object |
585
|
|
|
*/ |
586
|
|
|
protected function createItemBase( array $values = [], ?\Aimeos\MShop\Order\Item\Iface $basket = null ) : \Aimeos\MShop\Basket\Item\Iface |
587
|
|
|
{ |
588
|
|
|
return new \Aimeos\MShop\Basket\Item\Standard( $values, $basket ); |
589
|
|
|
} |
590
|
|
|
} |
591
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths