Standard   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A get() 0 14 3
A set() 0 3 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2025
6
 * @package Controller
7
 * @subpackage Common
8
 */
9
10
11
namespace Aimeos\Controller\Jobs\Common\Product\Import\Csv\Cache\Supplier;
12
13
14
/**
15
 * Category 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/supplier/name
25
	 * Name of the supplier cache implementation
26
	 *
27
	 * Use "Myname" if your class is named "\Aimeos\Controller\Jobs\Common\Product\Import\Csv\Cache\Supplier\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 $suppliers = [];
35
36
37
	/**
38
	 * Initializes the object
39
	 *
40
	 * @param \Aimeos\MShop\ContextIface $context Context object
41
	 */
42
	public function __construct( \Aimeos\MShop\ContextIface $context )
43
	{
44
		parent::__construct( $context );
45
46
		$manager = \Aimeos\MShop::create( $context, 'supplier' );
47
		$this->suppliers = $manager->search( $manager->filter(), ['address'] )->col( null, 'supplier.code' )->toArray();
48
	}
49
50
51
	/**
52
	 * Returns the supplier ID for the given code and type
53
	 *
54
	 * @param string $code Supplier code
55
	 * @param string|null $type Not used
56
	 * @return \Aimeos\MShop\Supplier\Item\Iface|null Supplier item or null if not found
57
	 */
58
	public function get( string $code, ?string $type = null )
59
	{
60
		if( isset( $this->suppliers[$code] ) ) {
61
			return $this->suppliers[$code];
62
		}
63
64
		$manager = \Aimeos\MShop::create( $this->context(), 'supplier' );
65
		$search = $manager->filter()->add( 'supplier.code', '==', $code );
66
67
		if( $item = $manager->search( $search, ['address'] )->first() ) {
68
			$this->suppliers[$code] = $item;
69
		}
70
71
		return $item;
72
	}
73
74
75
	/**
76
	 * Adds the supplier item to the cache
77
	 *
78
	 * @param \Aimeos\MShop\Common\Item\Iface $item Supplier object
79
	 */
80
	public function set( \Aimeos\MShop\Common\Item\Iface $item )
81
	{
82
		$this->suppliers[$item->getCode()] = $item;
83
	}
84
}
85