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