@@ 36-90 (lines=55) @@ | ||
33 | * @link https://github.com/techdivision/import-product-bundle |
|
34 | * @link http://www.techdivision.com |
|
35 | */ |
|
36 | class BundleOptionUpdateObserver extends BundleOptionObserver |
|
37 | { |
|
38 | ||
39 | /** |
|
40 | * Initialize the bundle option with the passed attributes and returns an instance. |
|
41 | * |
|
42 | * @param array $attr The bundle option attributes |
|
43 | * |
|
44 | * @return array The initialized bundle option |
|
45 | */ |
|
46 | protected function initializeBundleOption(array $attr) |
|
47 | { |
|
48 | ||
49 | // load the parent ID, the name and the store ID |
|
50 | $parentId = $attr[MemberNames::PARENT_ID]; |
|
51 | $name = $this->getValue(ColumnKeys::BUNDLE_VALUE_NAME); |
|
52 | $storeId = $this->getRowStoreId(StoreViewCodes::ADMIN); |
|
53 | ||
54 | // try to load the bundle option with the passed name/store/parent ID |
|
55 | if ($entity = $this->loadBundleOption($name, $storeId, $parentId)) { |
|
56 | return $this->mergeEntity($entity, $attr); |
|
57 | } |
|
58 | ||
59 | // simply return the attributes |
|
60 | return $attr; |
|
61 | } |
|
62 | ||
63 | /** |
|
64 | * Load's the bundle option with the passed name, store + parent ID. |
|
65 | * |
|
66 | * @param string $title The title of the bundle option to be returned |
|
67 | * @param integer $storeId The store ID of the bundle option to be returned |
|
68 | * @param integer $parentId The entity of the product the bundle option is related with |
|
69 | * |
|
70 | * @return array The bundle option |
|
71 | */ |
|
72 | protected function loadBundleOption($title, $storeId, $parentId) |
|
73 | { |
|
74 | return $this->getSubject()->loadBundleOption($title, $storeId, $parentId); |
|
75 | } |
|
76 | ||
77 | /** |
|
78 | * Return's the store ID of the actual row, or of the default store |
|
79 | * if no store view code is set in the CSV file. |
|
80 | * |
|
81 | * @param string|null $default The default store view code to use, if no store view code is set in the CSV file |
|
82 | * |
|
83 | * @return integer The ID of the actual store |
|
84 | * @throws \Exception Is thrown, if the store with the actual code is not available |
|
85 | */ |
|
86 | protected function getRowStoreId($default = null) |
|
87 | { |
|
88 | return $this->getSubject()->getRowStoreId($default); |
|
89 | } |
|
90 | } |
|
91 |
@@ 36-80 (lines=45) @@ | ||
33 | * @link https://github.com/techdivision/import-product-bundle |
|
34 | * @link http://www.techdivision.com |
|
35 | */ |
|
36 | class BundleSelectionPriceUpdateObserver extends BundleSelectionPriceObserver |
|
37 | { |
|
38 | ||
39 | /** |
|
40 | * Initialize the bundle selection price with the passed attributes and returns an instance. |
|
41 | * |
|
42 | * @param array $attr The bundle selection price attributes |
|
43 | * |
|
44 | * @return array The initialized bundle selection price |
|
45 | */ |
|
46 | protected function initializeBundleSelectionPrice(array $attr) |
|
47 | { |
|
48 | ||
49 | // load the store view code |
|
50 | $storeViewCode = $this->getStoreViewCode(StoreViewCodes::ADMIN); |
|
51 | ||
52 | // load the store/website ID |
|
53 | $store = $this->getStoreByStoreCode($storeViewCode); |
|
54 | $websiteId = $store[MemberNames::WEBSITE_ID]; |
|
55 | ||
56 | // load the selection ID for the child SKU |
|
57 | $selectionId = $this->getChildSkuSelectionMapping($this->getValue(ColumnKeys::BUNDLE_VALUE_SKU)); |
|
58 | ||
59 | // try to load the bundle selection price with the passed selection/website ID |
|
60 | if ($entity = $this->loadBundleSelectionPrice($selectionId, $websiteId)) { |
|
61 | return $this->mergeEntity($entity, $attr); |
|
62 | } |
|
63 | ||
64 | // simply return the attributes |
|
65 | return $attr; |
|
66 | } |
|
67 | ||
68 | /** |
|
69 | * Load's the bundle selection price with the passed selection/website ID. |
|
70 | * |
|
71 | * @param integer $selectionId The selection ID of the bundle selection price to be returned |
|
72 | * @param integer $websiteId The website ID of the bundle selection price to be returned |
|
73 | * |
|
74 | * @return array The bundle selection price |
|
75 | */ |
|
76 | protected function loadBundleSelectionPrice($selectionId, $websiteId) |
|
77 | { |
|
78 | return $this->getSubject()->loadBundleSelectionPrice($selectionId, $websiteId); |
|
79 | } |
|
80 | } |
|
81 |