-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathShopModifier.php
83 lines (72 loc) · 1.93 KB
/
ShopModifier.php
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
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace Makaira\Connect\Modifier\Common;
use Makaira\Connect\DatabaseInterface;
use Makaira\Connect\Modifier;
use Makaira\Connect\Type;
class ShopModifier extends Modifier
{
private $isMultiShop = false;
const SHOP_FIELD_SET_SIZE = 64;
protected $selectQuery = '
SELECT
OXSHOPID
FROM
%s
WHERE
OXMAPOBJECTID = :mapId;
';
/**
* @var DatabaseInterface
*/
private $database;
/**
* @param DatabaseInterface $database
* @param bool $isMultiShop
*/
public function __construct(DatabaseInterface $database, $isMultiShop, $mappingTable)
{
$this->database = $database;
$this->isMultiShop = $isMultiShop;
$this->selectQuery = sprintf($this->selectQuery, $mappingTable);
}
private function getArrayFromBitmask($bitmask)
{
$retArray = array();
for ($i = 0; $i < self::SHOP_FIELD_SET_SIZE; $i++) {
if (($bitmask >> $i) & 1) {
$retArray[] = $i + 1;
}
}
return $retArray;
}
/**
* Modify product and return modified product
*
* @param Type $product
*
* @return Type
*/
public function apply(Type $type)
{
if ($this->isMultiShop) {
if (empty($type->OXMAPID)) {
$bitmask = $type->OXSHOPINCL;
$type->shop = $this->getArrayFromBitmask($bitmask);
} else {
$type->shop = $this->database->query(
$this->selectQuery,
['mapId' => $type->OXMAPID]
);
$type->shop = array_map(
function ($x) {
return $x['OXSHOPID'];
},
$type->shop
);
}
} else {
$type->shop = [$type->OXSHOPID];
}
return $type;
}
}