1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
4
|
|
|
* @copyright Metaways Infosystems GmbH, 2012 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2018 |
6
|
|
|
* @package MShop |
7
|
|
|
* @subpackage Index |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\MShop\Index\Manager\Price; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Submanager for product prices. |
16
|
|
|
* |
17
|
|
|
* @package MShop |
18
|
|
|
* @subpackage Index |
19
|
|
|
*/ |
20
|
|
|
class Standard |
21
|
|
|
extends \Aimeos\MShop\Index\Manager\DBBase |
22
|
|
|
implements \Aimeos\MShop\Index\Manager\Price\Iface, \Aimeos\MShop\Common\Manager\Factory\Iface |
23
|
|
|
{ |
24
|
|
|
private $searchConfig = array( |
25
|
|
|
// @deprecated Removed 2019.01 |
26
|
|
|
'index.price.id' => array( |
27
|
|
|
'code' => 'index.price.id', |
28
|
|
|
'internalcode' => 'mindpr."prodid"', |
29
|
|
|
'internaldeps'=>array( 'LEFT JOIN "mshop_index_price" AS mindpr ON mindpr."prodid" = mpro."id"' ), |
30
|
|
|
'label' => 'Product index price ID', |
31
|
|
|
'type' => 'integer', |
32
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT, |
33
|
|
|
'public' => false, |
34
|
|
|
), |
35
|
|
|
'index.price:value' => array( |
36
|
|
|
'code' => 'index.price:value()', |
37
|
|
|
'internalcode' => ':site AND mindpr."currencyid" = $1 AND mindpr."value"', |
38
|
|
|
'label' => 'Product price value, parameter(<currency ID>)', |
39
|
|
|
'type' => 'null', |
40
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
41
|
|
|
'public' => false, |
42
|
|
|
), |
43
|
|
|
'sort:index.price:value' => array( |
44
|
|
|
'code' => 'sort:index.price:value()', |
45
|
|
|
'internalcode' => 'mindpr."value"', |
46
|
|
|
'label' => 'Sort product price value, parameter(<currency ID>)', |
47
|
|
|
'type' => 'null', |
48
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
49
|
|
|
'public' => false, |
50
|
|
|
), |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
private $subManagers; |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Initializes the manager instance. |
58
|
|
|
* |
59
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
60
|
|
|
*/ |
61
|
|
|
public function __construct( \Aimeos\MShop\Context\Item\Iface $context ) |
62
|
|
|
{ |
63
|
|
|
parent::__construct( $context ); |
64
|
|
|
|
65
|
|
|
$locale = $context->getLocale(); |
66
|
|
|
$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL; |
67
|
|
|
$level = $context->getConfig()->get( 'mshop/index/manager/sitemode', $level ); |
68
|
|
|
|
69
|
|
|
$siteIds = [$locale->getSiteId()]; |
70
|
|
|
|
71
|
|
|
if( $level & \Aimeos\MShop\Locale\Manager\Base::SITE_PATH ) { |
72
|
|
|
$siteIds = array_merge( $siteIds, $locale->getSitePath() ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
if( $level & \Aimeos\MShop\Locale\Manager\Base::SITE_SUBTREE ) { |
76
|
|
|
$siteIds = array_merge( $siteIds, $locale->getSiteSubTree() ); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$this->replaceSiteMarker( $this->searchConfig['index.price:value'], 'mindpr."siteid"', $siteIds ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Counts the number products that are available for the values of the given key. |
85
|
|
|
* |
86
|
|
|
* @param \Aimeos\MW\Criteria\Iface $search Search criteria |
87
|
|
|
* @param string $key Search key (usually the ID) to aggregate products for |
88
|
|
|
* @return integer[] List of ID values as key and the number of counted products as value |
89
|
|
|
*/ |
90
|
|
|
public function aggregate( \Aimeos\MW\Criteria\Iface $search, $key ) |
91
|
|
|
{ |
92
|
|
|
return $this->aggregateBase( $search, $key, 'mshop/index/manager/standard/aggregate' ); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Removes old entries from the storage. |
98
|
|
|
* |
99
|
|
|
* @param string[] $siteids List of IDs for sites whose entries should be deleted |
100
|
|
|
* @return \Aimeos\MShop\Index\Manager\Iface Manager object for chaining method calls |
101
|
|
|
*/ |
102
|
|
|
public function cleanup( array $siteids ) |
103
|
|
|
{ |
104
|
|
|
parent::cleanup( $siteids ); |
105
|
|
|
|
106
|
|
|
return $this->cleanupBase( $siteids, 'mshop/index/manager/price/standard/delete' ); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Removes all entries not touched after the given timestamp in the index. |
112
|
|
|
* This can be a long lasting operation. |
113
|
|
|
* |
114
|
|
|
* @param string $timestamp Timestamp in ISO format (YYYY-MM-DD HH:mm:ss) |
115
|
|
|
* @return \Aimeos\MShop\Index\Manager\Iface Manager object for chaining method calls |
116
|
|
|
*/ |
117
|
|
|
public function cleanupIndex( $timestamp ) |
118
|
|
|
{ |
119
|
|
|
/** mshop/index/manager/price/standard/cleanup/mysql |
120
|
|
|
* Deletes the index price records that haven't been touched |
121
|
|
|
* |
122
|
|
|
* @see mshop/index/manager/price/standard/cleanup/ansi |
123
|
|
|
*/ |
124
|
|
|
|
125
|
|
|
/** mshop/index/manager/price/standard/cleanup/ansi |
126
|
|
|
* Deletes the index price records that haven't been touched |
127
|
|
|
* |
128
|
|
|
* During the rebuild process of the product index, the entries of all |
129
|
|
|
* active products will be removed and readded. Thus, no stale data for |
130
|
|
|
* these products will remain in the database. |
131
|
|
|
* |
132
|
|
|
* All products that have been disabled since the last rebuild will be |
133
|
|
|
* still part of the index. The cleanup statement removes all records |
134
|
|
|
* that belong to products that haven't been touched during the index |
135
|
|
|
* rebuild because these are the disabled ones. |
136
|
|
|
* |
137
|
|
|
* The SQL statement should conform to the ANSI standard to be |
138
|
|
|
* compatible with most relational database systems. This also |
139
|
|
|
* includes using double quotes for table and column names. |
140
|
|
|
* |
141
|
|
|
* @param string SQL statement for deleting the outdated price index records |
142
|
|
|
* @since 2014.03 |
143
|
|
|
* @category Developer |
144
|
|
|
* @see mshop/index/manager/price/standard/count/ansi |
145
|
|
|
* @see mshop/index/manager/price/standard/delete/ansi |
146
|
|
|
* @see mshop/index/manager/price/standard/insert/ansi |
147
|
|
|
* @see mshop/index/manager/price/standard/search/ansi |
148
|
|
|
*/ |
149
|
|
|
return $this->cleanupIndexBase( $timestamp, 'mshop/index/manager/price/standard/cleanup' ); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Removes multiple items from the index. |
155
|
|
|
* |
156
|
|
|
* @param string[] $ids List of Product IDs |
157
|
|
|
*/ |
158
|
|
|
public function deleteItems( array $ids ) |
159
|
|
|
{ |
160
|
|
|
/** mshop/index/manager/price/standard/delete/mysql |
161
|
|
|
* Deletes the items matched by the given IDs from the database |
162
|
|
|
* |
163
|
|
|
* @see mshop/index/manager/price/standard/delete/ansi |
164
|
|
|
*/ |
165
|
|
|
|
166
|
|
|
/** mshop/index/manager/price/standard/delete/ansi |
167
|
|
|
* Deletes the items matched by the given IDs from the database |
168
|
|
|
* |
169
|
|
|
* Removes the records specified by the given IDs from the index database. |
170
|
|
|
* The records must be from the site that is configured via the |
171
|
|
|
* context item. |
172
|
|
|
* |
173
|
|
|
* The ":cond" placeholder is replaced by the name of the ID column and |
174
|
|
|
* the given ID or list of IDs while the site ID is bound to the question |
175
|
|
|
* mark. |
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 deleting index price records |
182
|
|
|
* @since 2014.03 |
183
|
|
|
* @category Developer |
184
|
|
|
* @see mshop/index/manager/price/standard/count/ansi |
185
|
|
|
* @see mshop/index/manager/price/standard/cleanup/ansi |
186
|
|
|
* @see mshop/index/manager/price/standard/insert/ansi |
187
|
|
|
* @see mshop/index/manager/price/standard/search/ansi |
188
|
|
|
*/ |
189
|
|
|
return $this->deleteItemsBase( $ids, 'mshop/index/manager/price/standard/delete' ); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Returns the available manager types |
195
|
|
|
* |
196
|
|
|
* @param boolean $withsub Return also the resource type of sub-managers if true |
197
|
|
|
* @return string[] Type of the manager and submanagers, subtypes are separated by slashes |
198
|
|
|
*/ |
199
|
|
|
public function getResourceType( $withsub = true ) |
200
|
|
|
{ |
201
|
|
|
$path = 'mshop/index/manager/price/submanagers'; |
202
|
|
|
|
203
|
|
|
return $this->getResourceTypeBase( 'index/price', $path, [], $withsub ); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Returns a list of objects describing the available criterias for searching. |
209
|
|
|
* |
210
|
|
|
* @param boolean $withsub Return also attributes of sub-managers if true |
211
|
|
|
* @return array List of items implementing \Aimeos\MW\Criteria\Attribute\Iface |
212
|
|
|
*/ |
213
|
|
|
public function getSearchAttributes( $withsub = true ) |
214
|
|
|
{ |
215
|
|
|
$list = parent::getSearchAttributes( $withsub ); |
216
|
|
|
|
217
|
|
|
/** mshop/index/manager/price/submanagers |
218
|
|
|
* List of manager names that can be instantiated by the index price manager |
219
|
|
|
* |
220
|
|
|
* Managers provide a generic interface to the underlying storage. |
221
|
|
|
* Each manager has or can have sub-managers caring about particular |
222
|
|
|
* aspects. Each of these sub-managers can be instantiated by its |
223
|
|
|
* parent manager using the getSubManager() method. |
224
|
|
|
* |
225
|
|
|
* The search keys from sub-managers can be normally used in the |
226
|
|
|
* manager as well. It allows you to search for items of the manager |
227
|
|
|
* using the search keys of the sub-managers to further limit the |
228
|
|
|
* retrieved list of items. |
229
|
|
|
* |
230
|
|
|
* @param array List of sub-manager names |
231
|
|
|
* @since 2014.03 |
232
|
|
|
* @category Developer |
233
|
|
|
*/ |
234
|
|
|
$path = 'mshop/index/manager/price/submanagers'; |
235
|
|
|
|
236
|
|
|
return $list + $this->getSearchAttributesBase( $this->searchConfig, $path, [], $withsub ); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Returns a new manager for product extensions. |
242
|
|
|
* |
243
|
|
|
* @param string $manager Name of the sub manager type in lower case |
244
|
|
|
* @param string|null $name Name of the implementation, will be from configuration (or Default) if null |
245
|
|
|
* @return \Aimeos\MShop\Common\Manager\Iface Manager for different extensions, e.g stock, tags, locations, etc. |
246
|
|
|
*/ |
247
|
|
|
public function getSubManager( $manager, $name = null ) |
248
|
|
|
{ |
249
|
|
|
/** mshop/index/manager/price/name |
250
|
|
|
* Class name of the used index price manager implementation |
251
|
|
|
* |
252
|
|
|
* Each default index price manager can be replaced by an alternative imlementation. |
253
|
|
|
* To use this implementation, you have to set the last part of the class |
254
|
|
|
* name as configuration value so the manager factory knows which class it |
255
|
|
|
* has to instantiate. |
256
|
|
|
* |
257
|
|
|
* For example, if the name of the default class is |
258
|
|
|
* |
259
|
|
|
* \Aimeos\MShop\Index\Manager\Price\Standard |
260
|
|
|
* |
261
|
|
|
* and you want to replace it with your own version named |
262
|
|
|
* |
263
|
|
|
* \Aimeos\MShop\Index\Manager\Price\Myprice |
264
|
|
|
* |
265
|
|
|
* then you have to set the this configuration option: |
266
|
|
|
* |
267
|
|
|
* mshop/index/manager/price/name = Myprice |
268
|
|
|
* |
269
|
|
|
* The value is the last part of your own class name and it's case sensitive, |
270
|
|
|
* so take care that the configuration value is exactly named like the last |
271
|
|
|
* part of the class name. |
272
|
|
|
* |
273
|
|
|
* The allowed characters of the class name are A-Z, a-z and 0-9. No other |
274
|
|
|
* characters are possible! You should always start the last part of the class |
275
|
|
|
* name with an upper case character and continue only with lower case characters |
276
|
|
|
* or numbers. Avoid chamel case names like "MyPrice"! |
277
|
|
|
* |
278
|
|
|
* @param string Last part of the class name |
279
|
|
|
* @since 2014.03 |
280
|
|
|
* @category Developer |
281
|
|
|
*/ |
282
|
|
|
|
283
|
|
|
/** mshop/index/manager/price/decorators/excludes |
284
|
|
|
* Excludes decorators added by the "common" option from the index price manager |
285
|
|
|
* |
286
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
287
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
288
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
289
|
|
|
* modify what is returned to the caller. |
290
|
|
|
* |
291
|
|
|
* This option allows you to remove a decorator added via |
292
|
|
|
* "mshop/common/manager/decorators/default" before they are wrapped |
293
|
|
|
* around the index price manager. |
294
|
|
|
* |
295
|
|
|
* mshop/index/manager/price/decorators/excludes = array( 'decorator1' ) |
296
|
|
|
* |
297
|
|
|
* This would remove the decorator named "decorator1" from the list of |
298
|
|
|
* common decorators ("\Aimeos\MShop\Common\Manager\Decorator\*") added via |
299
|
|
|
* "mshop/common/manager/decorators/default" for the index price manager. |
300
|
|
|
* |
301
|
|
|
* @param array List of decorator names |
302
|
|
|
* @since 2014.03 |
303
|
|
|
* @category Developer |
304
|
|
|
* @see mshop/common/manager/decorators/default |
305
|
|
|
* @see mshop/index/manager/price/decorators/global |
306
|
|
|
* @see mshop/index/manager/price/decorators/local |
307
|
|
|
*/ |
308
|
|
|
|
309
|
|
|
/** mshop/index/manager/price/decorators/global |
310
|
|
|
* Adds a list of globally available decorators only to the index price manager |
311
|
|
|
* |
312
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
313
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
314
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
315
|
|
|
* modify what is returned to the caller. |
316
|
|
|
* |
317
|
|
|
* This option allows you to wrap global decorators |
318
|
|
|
* ("\Aimeos\MShop\Common\Manager\Decorator\*") around the index price |
319
|
|
|
* manager. |
320
|
|
|
* |
321
|
|
|
* mshop/index/manager/price/decorators/global = array( 'decorator1' ) |
322
|
|
|
* |
323
|
|
|
* This would add the decorator named "decorator1" defined by |
324
|
|
|
* "\Aimeos\MShop\Common\Manager\Decorator\Decorator1" only to the index |
325
|
|
|
* price manager. |
326
|
|
|
* |
327
|
|
|
* @param array List of decorator names |
328
|
|
|
* @since 2014.03 |
329
|
|
|
* @category Developer |
330
|
|
|
* @see mshop/common/manager/decorators/default |
331
|
|
|
* @see mshop/index/manager/price/decorators/excludes |
332
|
|
|
* @see mshop/index/manager/price/decorators/local |
333
|
|
|
*/ |
334
|
|
|
|
335
|
|
|
/** mshop/index/manager/price/decorators/local |
336
|
|
|
* Adds a list of local decorators only to the index price manager |
337
|
|
|
* |
338
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
339
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
340
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
341
|
|
|
* modify what is returned to the caller. |
342
|
|
|
* |
343
|
|
|
* This option allows you to wrap local decorators |
344
|
|
|
* ("\Aimeos\MShop\Index\Manager\Price\Decorator\*") around the index |
345
|
|
|
* price manager. |
346
|
|
|
* |
347
|
|
|
* mshop/index/manager/price/decorators/local = array( 'decorator2' ) |
348
|
|
|
* |
349
|
|
|
* This would add the decorator named "decorator2" defined by |
350
|
|
|
* "\Aimeos\MShop\Index\Manager\Price\Decorator\Decorator2" only to the |
351
|
|
|
* index price manager. |
352
|
|
|
* |
353
|
|
|
* @param array List of decorator names |
354
|
|
|
* @since 2014.03 |
355
|
|
|
* @category Developer |
356
|
|
|
* @see mshop/common/manager/decorators/default |
357
|
|
|
* @see mshop/index/manager/price/decorators/excludes |
358
|
|
|
* @see mshop/index/manager/price/decorators/global |
359
|
|
|
*/ |
360
|
|
|
|
361
|
|
|
return $this->getSubManagerBase( 'index', 'price/' . $manager, $name ); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* Optimizes the index if necessary. |
367
|
|
|
* Execution of this operation can take a very long time and shouldn't be |
368
|
|
|
* called through a web server enviroment. |
369
|
|
|
* |
370
|
|
|
* @return \Aimeos\MShop\Index\Manager\Iface Manager object for chaining method calls |
371
|
|
|
*/ |
372
|
|
|
public function optimize() |
373
|
|
|
{ |
374
|
|
|
/** mshop/index/manager/price/standard/optimize/mysql |
375
|
|
|
* Optimizes the stored price data for retrieving the records faster |
376
|
|
|
* |
377
|
|
|
* @see mshop/index/manager/price/standard/optimize/ansi |
378
|
|
|
*/ |
379
|
|
|
|
380
|
|
|
/** mshop/index/manager/price/standard/optimize/ansi |
381
|
|
|
* Optimizes the stored price data for retrieving the records faster |
382
|
|
|
* |
383
|
|
|
* The SQL statement should reorganize the data in the DBMS storage to |
384
|
|
|
* optimize access to the records of the table or tables. Some DBMS |
385
|
|
|
* offer specialized statements to optimize indexes and records. This |
386
|
|
|
* statement doesn't return any records. |
387
|
|
|
* |
388
|
|
|
* The SQL statement should conform to the ANSI standard to be |
389
|
|
|
* compatible with most relational database systems. This also |
390
|
|
|
* includes using double quotes for table and column names. |
391
|
|
|
* |
392
|
|
|
* @param string SQL statement for optimizing the stored price data |
393
|
|
|
* @since 2014.09 |
394
|
|
|
* @category Developer |
395
|
|
|
* @see mshop/index/manager/price/standard/count/ansi |
396
|
|
|
* @see mshop/index/manager/price/standard/search/ansi |
397
|
|
|
* @see mshop/index/manager/price/standard/aggregate/ansi |
398
|
|
|
*/ |
399
|
|
|
return $this->optimizeBase( 'mshop/index/manager/price/standard/optimize' ); |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* Rebuilds the index price for searching products or specified list of products. |
405
|
|
|
* This can be a long lasting operation. |
406
|
|
|
* |
407
|
|
|
* @param \Aimeos\MShop\Product\Item\Iface[] $items Associative list of product IDs as keys and items as values |
408
|
|
|
* @return \Aimeos\MShop\Index\Manager\Iface Manager object for chaining method calls |
409
|
|
|
*/ |
410
|
|
|
public function rebuildIndex( array $items = [] ) |
411
|
|
|
{ |
412
|
|
|
if( empty( $items ) ) { return $this; } |
413
|
|
|
|
414
|
|
|
\Aimeos\MW\Common\Base::checkClassList( \Aimeos\MShop\Product\Item\Iface::class, $items ); |
415
|
|
|
|
416
|
|
|
$context = $this->getContext(); |
417
|
|
|
$dbm = $context->getDatabaseManager(); |
418
|
|
|
$dbname = $this->getResourceName(); |
419
|
|
|
$conn = $dbm->acquire( $dbname ); |
420
|
|
|
|
421
|
|
|
try |
422
|
|
|
{ |
423
|
|
|
/** mshop/index/manager/price/standard/insert/mysql |
424
|
|
|
* Inserts a new price record into the product index database |
425
|
|
|
* |
426
|
|
|
* @see mshop/index/manager/price/standard/insert/ansi |
427
|
|
|
*/ |
428
|
|
|
|
429
|
|
|
/** mshop/index/manager/price/standard/insert/ansi |
430
|
|
|
* Inserts a new price record into the product index database |
431
|
|
|
* |
432
|
|
|
* During the product index rebuild, prices related to a product |
433
|
|
|
* will be stored in the index for this product. All records |
434
|
|
|
* are deleted before the new ones are inserted. |
435
|
|
|
* |
436
|
|
|
* The SQL statement must be a string suitable for being used as |
437
|
|
|
* prepared statement. It must include question marks for binding |
438
|
|
|
* the values from the order item to the statement before they are |
439
|
|
|
* sent to the database server. The number of question marks must |
440
|
|
|
* be the same as the number of columns listed in the INSERT |
441
|
|
|
* statement. The order of the columns must correspond to the |
442
|
|
|
* order in the rebuildIndex() method, so the correct values are |
443
|
|
|
* bound to the columns. |
444
|
|
|
* |
445
|
|
|
* The SQL statement should conform to the ANSI standard to be |
446
|
|
|
* compatible with most relational database systems. This also |
447
|
|
|
* includes using double quotes for table and column names. |
448
|
|
|
* |
449
|
|
|
* @param string SQL statement for inserting records |
450
|
|
|
* @since 2014.03 |
451
|
|
|
* @category Developer |
452
|
|
|
* @see mshop/index/manager/price/standard/cleanup/ansi |
453
|
|
|
* @see mshop/index/manager/price/standard/delete/ansi |
454
|
|
|
* @see mshop/index/manager/price/standard/search/ansi |
455
|
|
|
* @see mshop/index/manager/price/standard/count/ansi |
456
|
|
|
*/ |
457
|
|
|
$stmt = $this->getCachedStatement( $conn, 'mshop/index/manager/price/standard/insert' ); |
458
|
|
|
|
459
|
|
|
foreach( $items as $item ) { |
460
|
|
|
$this->savePrices( $stmt, $item ); |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
$dbm->release( $conn, $dbname ); |
464
|
|
|
} |
465
|
|
|
catch( \Exception $e ) |
466
|
|
|
{ |
467
|
|
|
$dbm->release( $conn, $dbname ); |
468
|
|
|
throw $e; |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
foreach( $this->getSubManagers() as $submanager ) { |
472
|
|
|
$submanager->rebuildIndex( $items ); |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
return $this; |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
|
479
|
|
|
/** |
480
|
|
|
* Searches for items matching the given criteria. |
481
|
|
|
* |
482
|
|
|
* @param \Aimeos\MW\Criteria\Iface $search Search criteria object |
483
|
|
|
* @param string[] $ref List of domains to fetch list items and referenced items for |
484
|
|
|
* @param integer|null &$total Number of items that are available in total |
485
|
|
|
* @return array List of items implementing \Aimeos\MShop\Product\Item\Iface with ids as keys |
486
|
|
|
*/ |
487
|
|
|
public function searchItems( \Aimeos\MW\Criteria\Iface $search, array $ref = [], &$total = null ) |
488
|
|
|
{ |
489
|
|
|
/** mshop/index/manager/price/standard/search/mysql |
490
|
|
|
* Retrieves the records matched by the given criteria in the database |
491
|
|
|
* |
492
|
|
|
* @see mshop/index/manager/price/standard/search/ansi |
493
|
|
|
*/ |
494
|
|
|
|
495
|
|
|
/** mshop/index/manager/price/standard/search/ansi |
496
|
|
|
* Retrieves the records matched by the given criteria in the database |
497
|
|
|
* |
498
|
|
|
* Fetches the records matched by the given criteria from the product index |
499
|
|
|
* database. The records must be from one of the sites that are |
500
|
|
|
* configured via the context item. If the current site is part of |
501
|
|
|
* a tree of sites, the SELECT statement can retrieve all records |
502
|
|
|
* from the current site and the complete sub-tree of sites. |
503
|
|
|
* |
504
|
|
|
* As the records can normally be limited by criteria from sub-managers, |
505
|
|
|
* their tables must be joined in the SQL context. This is done by |
506
|
|
|
* using the "internaldeps" property from the definition of the ID |
507
|
|
|
* column of the sub-managers. These internal dependencies specify |
508
|
|
|
* the JOIN between the tables and the used columns for joining. The |
509
|
|
|
* ":joins" placeholder is then replaced by the JOIN strings from |
510
|
|
|
* the sub-managers. |
511
|
|
|
* |
512
|
|
|
* To limit the records matched, conditions can be added to the given |
513
|
|
|
* criteria object. It can contain comparisons like column names that |
514
|
|
|
* must match specific values which can be combined by AND, OR or NOT |
515
|
|
|
* operators. The resulting string of SQL conditions replaces the |
516
|
|
|
* ":cond" placeholder before the statement is sent to the database |
517
|
|
|
* server. |
518
|
|
|
* |
519
|
|
|
* If the records that are retrieved should be ordered by one or more |
520
|
|
|
* columns, the generated string of column / sort direction pairs |
521
|
|
|
* replaces the ":order" placeholder. In case no ordering is required, |
522
|
|
|
* the complete ORDER BY part including the "\/*-orderby*\/...\/*orderby-*\/" |
523
|
|
|
* markers is removed to speed up retrieving the records. Columns of |
524
|
|
|
* sub-managers can also be used for ordering the result set but then |
525
|
|
|
* no index can be used. |
526
|
|
|
* |
527
|
|
|
* The number of returned records can be limited and can start at any |
528
|
|
|
* number between the begining and the end of the result set. For that |
529
|
|
|
* the ":size" and ":start" placeholders are replaced by the |
530
|
|
|
* corresponding values from the criteria object. The default values |
531
|
|
|
* are 0 for the start and 100 for the size value. |
532
|
|
|
* |
533
|
|
|
* The SQL statement should conform to the ANSI standard to be |
534
|
|
|
* compatible with most relational database systems. This also |
535
|
|
|
* includes using double quotes for table and column names. |
536
|
|
|
* |
537
|
|
|
* @param string SQL statement for searching items |
538
|
|
|
* @since 2014.03 |
539
|
|
|
* @category Developer |
540
|
|
|
* @see mshop/index/manager/price/standard/count/ansi |
541
|
|
|
* @see mshop/index/manager/price/standard/optimize/ansi |
542
|
|
|
* @see mshop/index/manager/price/standard/aggregate/ansi |
543
|
|
|
*/ |
544
|
|
|
$cfgPathSearch = 'mshop/index/manager/price/standard/search'; |
545
|
|
|
|
546
|
|
|
/** mshop/index/manager/price/standard/count/mysql |
547
|
|
|
* Counts the number of records matched by the given criteria in the database |
548
|
|
|
* |
549
|
|
|
* @see mshop/index/manager/price/standard/count/ansi |
550
|
|
|
*/ |
551
|
|
|
|
552
|
|
|
/** mshop/index/manager/price/standard/count/ansi |
553
|
|
|
* Counts the number of records matched by the given criteria in the database |
554
|
|
|
* |
555
|
|
|
* Counts all records matched by the given criteria from the product index |
556
|
|
|
* database. The records must be from one of the sites that are |
557
|
|
|
* configured via the context item. If the current site is part of |
558
|
|
|
* a tree of sites, the statement can count all records from the |
559
|
|
|
* current site and the complete sub-tree of sites. |
560
|
|
|
* |
561
|
|
|
* As the records can normally be limited by criteria from sub-managers, |
562
|
|
|
* their tables must be joined in the SQL context. This is done by |
563
|
|
|
* using the "internaldeps" property from the definition of the ID |
564
|
|
|
* column of the sub-managers. These internal dependencies specify |
565
|
|
|
* the JOIN between the tables and the used columns for joining. The |
566
|
|
|
* ":joins" placeholder is then replaced by the JOIN strings from |
567
|
|
|
* the sub-managers. |
568
|
|
|
* |
569
|
|
|
* To limit the records matched, conditions can be added to the given |
570
|
|
|
* criteria object. It can contain comparisons like column names that |
571
|
|
|
* must match specific values which can be combined by AND, OR or NOT |
572
|
|
|
* operators. The resulting string of SQL conditions replaces the |
573
|
|
|
* ":cond" placeholder before the statement is sent to the database |
574
|
|
|
* server. |
575
|
|
|
* |
576
|
|
|
* Both, the strings for ":joins" and for ":cond" are the same as for |
577
|
|
|
* the "search" SQL statement. |
578
|
|
|
* |
579
|
|
|
* Contrary to the "search" statement, it doesn't return any records |
580
|
|
|
* but instead the number of records that have been found. As counting |
581
|
|
|
* thousands of records can be a long running task, the maximum number |
582
|
|
|
* of counted records is limited for performance reasons. |
583
|
|
|
* |
584
|
|
|
* The SQL statement should conform to the ANSI standard to be |
585
|
|
|
* compatible with most relational database systems. This also |
586
|
|
|
* includes using double quotes for table and column names. |
587
|
|
|
* |
588
|
|
|
* @param string SQL statement for counting items |
589
|
|
|
* @since 2014.03 |
590
|
|
|
* @category Developer |
591
|
|
|
* @see mshop/index/manager/price/standard/search/ansi |
592
|
|
|
* @see mshop/index/manager/price/standard/optimize/ansi |
593
|
|
|
* @see mshop/index/manager/price/standard/aggregate/ansi |
594
|
|
|
*/ |
595
|
|
|
$cfgPathCount = 'mshop/index/manager/price/standard/count'; |
596
|
|
|
|
597
|
|
|
return $this->searchItemsIndexBase( $search, $ref, $total, $cfgPathSearch, $cfgPathCount ); |
598
|
|
|
} |
599
|
|
|
|
600
|
|
|
|
601
|
|
|
/** |
602
|
|
|
* Returns the list of sub-managers available for the index attribute manager. |
603
|
|
|
* |
604
|
|
|
* @return \Aimeos\MShop\Index\Manager\Iface Associative list of the sub-domain as key and the manager object as value |
605
|
|
|
*/ |
606
|
|
|
protected function getSubManagers() |
607
|
|
|
{ |
608
|
|
|
if( $this->subManagers === null ) |
609
|
|
|
{ |
610
|
|
|
$this->subManagers = []; |
611
|
|
|
|
612
|
|
|
/** mshop/index/manager/price/submanagers |
613
|
|
|
* A list of sub-manager names used for indexing associated items to prices |
614
|
|
|
* |
615
|
|
|
* All items referenced by a product (e.g. texts, prices, media, |
616
|
|
|
* etc.) are added to the product index via specialized index |
617
|
|
|
* managers. You can add the name of new sub-managers to add more |
618
|
|
|
* data to the index or remove existing ones if you don't want to |
619
|
|
|
* index that data at all. |
620
|
|
|
* |
621
|
|
|
* This option configures the sub-managers that cares about |
622
|
|
|
* indexing data associated to product prices. |
623
|
|
|
* |
624
|
|
|
* @param string List of index sub-manager names |
625
|
|
|
* @since 2014.09 |
626
|
|
|
* @category User |
627
|
|
|
* @category Developer |
628
|
|
|
* @see mshop/index/manager/standard/submanagers |
629
|
|
|
*/ |
630
|
|
|
$path = 'mshop/index/manager/price/submanagers'; |
631
|
|
|
|
632
|
|
|
foreach( $this->getContext()->getConfig()->get( $path, [] ) as $domain ) { |
633
|
|
|
$this->subManagers[$domain] = $this->getObject()->getSubManager( $domain ); |
634
|
|
|
} |
635
|
|
|
|
636
|
|
|
return $this->subManagers; |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
return $this->subManagers; |
640
|
|
|
} |
641
|
|
|
|
642
|
|
|
|
643
|
|
|
/** |
644
|
|
|
* Saves the text items referenced indirectly by products |
645
|
|
|
* |
646
|
|
|
* @param \Aimeos\MW\DB\Statement\Iface $stmt Prepared SQL statement with place holders |
647
|
|
|
* @param \Aimeos\MShop\Product\Item\Iface $item Product item containing associated price items |
648
|
|
|
*/ |
649
|
|
|
protected function savePrices( \Aimeos\MW\DB\Statement\Iface $stmt, \Aimeos\MShop\Common\Item\ListRef\Iface $item ) |
650
|
|
|
{ |
651
|
|
|
$prices = []; |
652
|
|
|
$date = date( 'Y-m-d H:i:s' ); |
653
|
|
|
$context = $this->getContext(); |
654
|
|
|
$siteid = $context->getLocale()->getSiteId(); |
655
|
|
|
|
656
|
|
|
/** mshop/index/manager/price/types |
657
|
|
|
* Use different product prices types for indexing |
658
|
|
|
* |
659
|
|
|
* In some cases, prices are stored with different types, eg. price per kg. |
660
|
|
|
* This configuration option defines which types are incorporated in which |
661
|
|
|
* order. If a price of the defined type with the lowest index is available, |
662
|
|
|
* it will be indexed, otherwise the next lowest index price type. It is |
663
|
|
|
* highly recommended to add the price type 'default' with the highest index. |
664
|
|
|
* |
665
|
|
|
* @param array List of price types codes |
666
|
|
|
* @since 2019.04 |
667
|
|
|
* @category Developer |
668
|
|
|
*/ |
669
|
|
|
$types = $context->getConfig()->get( 'mshop/index/manager/price/types', ['default'] ); |
670
|
|
|
|
671
|
|
|
foreach( $types as $priceType ) |
672
|
|
|
{ |
673
|
|
|
foreach( $item->getListItems( 'price', 'default', $priceType ) as $listItem ) |
674
|
|
|
{ |
675
|
|
|
if( ( $refItem = $listItem->getRefItem() ) !== null |
676
|
|
|
&& $refItem->isAvailable() |
677
|
|
|
&& !isset ( $prices[$refItem->getCurrencyId()][$refItem->getQuantity()] ) |
678
|
|
|
) { |
679
|
|
|
$prices[$refItem->getCurrencyId()][$refItem->getQuantity()] = $refItem->getValue(); |
680
|
|
|
} |
681
|
|
|
} |
682
|
|
|
} |
683
|
|
|
|
684
|
|
|
foreach( $prices as $currencyId => $list ) |
685
|
|
|
{ |
686
|
|
|
ksort( $list ); |
687
|
|
|
|
688
|
|
|
$stmt->bind( 1, $item->getId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
689
|
|
|
$stmt->bind( 2, $currencyId ); |
690
|
|
|
$stmt->bind( 3, reset( $list ) ); |
691
|
|
|
$stmt->bind( 4, $date ); // mtime |
692
|
|
|
$stmt->bind( 5, $siteid, \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
693
|
|
|
|
694
|
|
|
try { |
695
|
|
|
$stmt->execute()->finish(); |
696
|
|
|
} catch( \Aimeos\MW\DB\Exception $e ) { ; } // Ignore duplicates |
697
|
|
|
} |
698
|
|
|
} |
699
|
|
|
} |
700
|
|
|
|