1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* @copyright Vertex. All rights reserved. https://www.vertexinc.com/
* @author Mediotype https://www.mediotype.com/
*/
namespace Vertex\Tax\Model\ResourceModel;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\Model\ResourceModel\Db\Context;
use Vertex\Tax\Model\ResourceModel\CustomerCode\Collection;
use Vertex\Tax\Model\ResourceModel\CustomerCode\CollectionFactory;
/**
* Performs Datastore-related actions for the CustomerCode repository
*/
class CustomerCode extends AbstractDb
{
const TABLE = 'vertex_customer_code';
const FIELD_ID = 'customer_id';
const FIELD_CODE = 'customer_code';
/** @var CollectionFactory */
private $collectionFactory;
/**
* @param Context $context
* @param CollectionFactory $collectionFactory
* @param string|null $connectionName
*/
public function __construct(Context $context, CollectionFactory $collectionFactory, $connectionName = null)
{
parent::__construct($context, $connectionName);
$this->collectionFactory = $collectionFactory;
}
/**
* @inheritdoc
*
* MEQP2 Warning: Protected method. Needed to override AbstractDb's _construct
*/
protected function _construct()
{
$this->_isPkAutoIncrement = false;
$this->_init(static::TABLE, static::FIELD_ID);
}
/**
* Retrieve a list of Customer Codes indexed by Customer ID
*
* @param int[] $customerIds
* @return \Vertex\Tax\Model\Data\CustomerCode[]
*/
public function getArrayByCustomerIds($customerIds)
{
/** @var Collection $collection */
$collection = $this->collectionFactory->create();
$collection->addFieldToFilter(static::FIELD_ID, ['in' => $customerIds]);
$collection->load();
$result = [];
foreach ($collection->getItems() as $item) {
/** @var \Vertex\Tax\Model\Data\CustomerCode $item */
$result[$item->getCustomerId()] = $item;
}
return $result;
}
}