1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Product\TierPrice\Observers\TierPriceUpdateObserver |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Klaas-Tido Rühl <[email protected]> |
15
|
|
|
* @author Tim Wagner <[email protected]> |
16
|
|
|
* @copyright 2019 REFUSiON GmbH <[email protected]> |
17
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
18
|
|
|
* @link https://github.com/techdivision/import-product-tier-price |
19
|
|
|
* @link https://www.techdivision.com |
20
|
|
|
* @link https://www.refusion.com |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace TechDivision\Import\Product\TierPrice\Observers; |
24
|
|
|
|
25
|
|
|
use TechDivision\Import\Product\TierPrice\Utils\MemberNames; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Observer for creating/updating/deleting tier prices from the database. |
29
|
|
|
* |
30
|
|
|
* @author Klaas-Tido Rühl <[email protected]> |
31
|
|
|
* @author Tim Wagner <[email protected]> |
32
|
|
|
* @copyright 2019 REFUSiON GmbH <[email protected]> |
33
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
34
|
|
|
* @link https://github.com/techdivision/import-product-tier-price |
35
|
|
|
* @link https://www.techdivision.com |
36
|
|
|
* @link https://www.refusion.com |
37
|
|
|
*/ |
38
|
|
|
class TierPriceUpdateObserver extends TierPriceObserver |
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Initialize the product website with the passed attributes and returns an instance. |
43
|
|
|
* |
44
|
|
|
* @param array $attr The product website attributes |
45
|
|
|
* |
46
|
|
|
* @return array The initialized product website |
47
|
|
|
* @throws \RuntimeException Is thrown, if the attributes can not be initialized |
48
|
|
|
*/ |
49
|
|
|
protected function initializeTierPrice(array $attr) |
50
|
|
|
{ |
51
|
|
|
|
52
|
|
|
// load the unique key parameters |
53
|
|
|
$pk = $attr[$this->getPrimaryKeyMemberName()]; |
54
|
|
|
$qty = $attr[MemberNames::QTY]; |
55
|
|
|
$allGroups = $attr[MemberNames::ALL_GROUPS]; |
56
|
|
|
$websiteId = $attr[MemberNames::WEBSITE_ID]; |
57
|
|
|
$customerGroupId = $attr[MemberNames::CUSTOMER_GROUP_ID]; |
58
|
|
|
|
59
|
|
|
// try load the product by the given SKU |
60
|
|
|
if ($entity = $this->loadTierPriceByPkAndAllGroupsAndCustomerGroupIdAndQtyAndWebsiteId($pk, $allGroups, $customerGroupId, $qty, $websiteId)) { |
61
|
|
|
return $this->mergeEntity($entity, $attr); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// return the the attributes |
65
|
|
|
return $attr; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Returns the tier price with the given parameters. |
70
|
|
|
* |
71
|
|
|
* @param string $pk The PK of the product relation |
72
|
|
|
* @param integer $allGroups The flag if all groups are affected or not |
73
|
|
|
* @param integer $customerGroupId The customer group ID |
74
|
|
|
* @param integer $qty The tier price quantity |
75
|
|
|
* @param integer $websiteId The website ID the tier price is related to |
76
|
|
|
* |
77
|
|
|
* @return array The tier price |
78
|
|
|
*/ |
79
|
|
|
protected function loadTierPriceByPkAndAllGroupsAndCustomerGroupIdAndQtyAndWebsiteId($pk, $allGroups, $customerGroupId, $qty, $websiteId) |
80
|
|
|
{ |
81
|
|
|
return $this->getTierPriceProcessor()->loadTierPriceByPkAndAllGroupsAndCustomerGroupIdAndQtyAndWebsiteId($pk, $allGroups, $customerGroupId, $qty, $websiteId); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|