| @@ 34-73 (lines=40) @@ | ||
| 31 | * @link https://github.com/techdivision/import-product-link |
|
| 32 | * @link http://www.techdivision.com |
|
| 33 | */ |
|
| 34 | class LinkAttributePositionUpdateObserver extends LinkAttributePositionObserver |
|
| 35 | { |
|
| 36 | ||
| 37 | /** |
|
| 38 | * Initialize the product link attribute with the passed attributes and returns an instance. |
|
| 39 | * |
|
| 40 | * @param array $attr The product link attribute |
|
| 41 | * |
|
| 42 | * @return array The initialized product link attribute |
|
| 43 | */ |
|
| 44 | protected function initializeProductLinkAttributeInt(array $attr) |
|
| 45 | { |
|
| 46 | ||
| 47 | // load value/link/product link attribute ID |
|
| 48 | $value = $attr[MemberNames::VALUE]; |
|
| 49 | $linkId = $attr[MemberNames::LINK_ID]; |
|
| 50 | $productLinkAttributeId = $attr[MemberNames::PRODUCT_LINK_ATTRIBUTE_ID]; |
|
| 51 | ||
| 52 | // try to load the product link attribute integer value with the passed product link attribute/link ID |
|
| 53 | if ($entity = $this->loadProductLinkAttributeInt($productLinkAttributeId, $linkId)) { |
|
| 54 | return $this->mergeEntity($entity, $attr); |
|
| 55 | } |
|
| 56 | ||
| 57 | // simply return the attributes |
|
| 58 | return $attr; |
|
| 59 | } |
|
| 60 | ||
| 61 | /** |
|
| 62 | * Return's the product link attribute integer value with the passed product link attribute/link ID. |
|
| 63 | * |
|
| 64 | * @param integer $productLinkAttributeId The product link attribute ID of the attributes |
|
| 65 | * @param integer $linkId The link ID of the attribute |
|
| 66 | * |
|
| 67 | * @return array The product link attribute integer value |
|
| 68 | */ |
|
| 69 | protected function loadProductLinkAttributeInt($productLinkAttributeId, $linkId) |
|
| 70 | { |
|
| 71 | return $this->getSubject()->loadProductLinkAttributeInt($productLinkAttributeId, $linkId); |
|
| 72 | } |
|
| 73 | } |
|
| 74 | ||
| @@ 34-74 (lines=41) @@ | ||
| 31 | * @link https://github.com/techdivision/import-product-link |
|
| 32 | * @link http://www.techdivision.com |
|
| 33 | */ |
|
| 34 | class LinkUpdateObserver extends LinkObserver |
|
| 35 | { |
|
| 36 | ||
| 37 | /** |
|
| 38 | * Initialize the product link with the passed attributes and returns an instance. |
|
| 39 | * |
|
| 40 | * @param array $attr The product link attributes |
|
| 41 | * |
|
| 42 | * @return array The initialized product link |
|
| 43 | */ |
|
| 44 | protected function initializeProductLink(array $attr) |
|
| 45 | { |
|
| 46 | ||
| 47 | // load the product/linked product/link type ID |
|
| 48 | $productId = $attr[MemberNames::PRODUCT_ID]; |
|
| 49 | $linkTypeId = $attr[MemberNames::LINK_TYPE_ID]; |
|
| 50 | $linkedProductId = $attr[MemberNames::LINKED_PRODUCT_ID]; |
|
| 51 | ||
| 52 | // try to load the link with the passed product/linked product/link type ID |
|
| 53 | if ($entity = $this->loadProductLink($productId, $linkedProductId, $linkTypeId)) { |
|
| 54 | return $this->mergeEntity($entity, $attr); |
|
| 55 | } |
|
| 56 | ||
| 57 | // simply return the attributes |
|
| 58 | return $attr; |
|
| 59 | } |
|
| 60 | ||
| 61 | /** |
|
| 62 | * Load's the link with the passed product/linked product/link type ID. |
|
| 63 | * |
|
| 64 | * @param integer $productId The product ID of the link to load |
|
| 65 | * @param integer $linkedProductId The linked product ID of the link to load |
|
| 66 | * @param integer $linkTypeId The link type ID of the product to load |
|
| 67 | * |
|
| 68 | * @return array The link |
|
| 69 | */ |
|
| 70 | protected function loadProductLink($productId, $linkedProductId, $linkTypeId) |
|
| 71 | { |
|
| 72 | return $this->getSubject()->loadProductLink($productId, $linkedProductId, $linkTypeId); |
|
| 73 | } |
|
| 74 | } |
|
| 75 | ||