1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2023 |
6
|
|
|
* @package Controller |
7
|
|
|
* @subpackage Common |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Controller\Jobs\Common\Product\Import\Csv\Cache\Product; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Product cache for CSV imports |
16
|
|
|
* |
17
|
|
|
* @package Controller |
18
|
|
|
* @subpackage Common |
19
|
|
|
*/ |
20
|
|
|
class Standard |
21
|
|
|
extends \Aimeos\Controller\Jobs\Common\Product\Import\Csv\Cache\Base |
22
|
|
|
implements \Aimeos\Controller\Jobs\Common\Product\Import\Csv\Cache\Iface |
23
|
|
|
{ |
24
|
|
|
/** controller/jobs/product/import/csv/cache/product/name |
25
|
|
|
* Name of the product cache implementation |
26
|
|
|
* |
27
|
|
|
* Use "Myname" if your class is named "\Aimeos\Controller\Jobs\Common\Product\Import\Csv\Cache\Product\Myname". |
28
|
|
|
* The name is case-sensitive and you should avoid camel case names like "MyName". |
29
|
|
|
* |
30
|
|
|
* @param string Last part of the cache class name |
31
|
|
|
* @since 2015.10 |
32
|
|
|
*/ |
33
|
|
|
|
34
|
|
|
private array $prodmap = []; |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Returns the product ID for the given code |
39
|
|
|
* |
40
|
|
|
* @param string $code Product code |
41
|
|
|
* @param string|null $type Attribute type |
42
|
|
|
* @return string|null Product ID or null if not found |
43
|
|
|
*/ |
44
|
|
|
public function get( string $code, string $type = null ) |
45
|
|
|
{ |
46
|
|
|
if( isset( $this->prodmap[$code] ) ) { |
47
|
|
|
return $this->prodmap[$code]; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$manager = \Aimeos\MShop::create( $this->context(), 'product' ); |
51
|
|
|
|
52
|
|
|
$search = $manager->filter(); |
53
|
|
|
$search->setConditions( $search->compare( '==', 'product.code', $code ) ); |
54
|
|
|
|
55
|
|
|
if( ( $item = $manager->search( $search )->first() ) !== null ) |
56
|
|
|
{ |
57
|
|
|
$this->prodmap[$code] = $item->getId(); |
58
|
|
|
return $this->prodmap[$code]; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Adds the product ID to the cache |
65
|
|
|
* |
66
|
|
|
* @param \Aimeos\MShop\Common\Item\Iface $item Product object |
67
|
|
|
*/ |
68
|
|
|
public function set( \Aimeos\MShop\Common\Item\Iface $item ) |
69
|
|
|
{ |
70
|
|
|
$this->prodmap[$item->getCode()] = $item->getId(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|