Public Member Functions | |
assign ($type, $productId, $linkedProductId, $data=array()) | |
update ($type, $productId, $linkedProductId, $data=array()) |
Definition at line 34 of file V2.php.
assign | ( | $ | type, | |
$ | productId, | |||
$ | linkedProductId, | |||
$ | data = array() | |||
) |
Add product link association
string | $type | |
int|string | $productId | |
int|string | $linkedProductId | |
array | $data |
Reimplemented from Mage_Catalog_Model_Product_Link_Api.
Definition at line 45 of file V2.php.
00046 { 00047 $typeId = $this->_getTypeId($type); 00048 00049 $product = $this->_initProduct($productId); 00050 00051 $link = $product->getLinkInstance() 00052 ->setLinkTypeId($typeId); 00053 00054 $collection = $this->_initCollection($link, $product); 00055 $idBySku = $product->getIdBySku($linkedProductId); 00056 if ($idBySku) { 00057 $linkedProductId = $idBySku; 00058 } 00059 00060 $links = $this->_collectionToEditableArray($collection); 00061 00062 $links[(int)$linkedProductId] = array(); 00063 foreach ($collection->getLinkModel()->getAttributes() as $attribute) { 00064 if (isset($data->$attribute['code'])) { 00065 $links[(int)$linkedProductId][$attribute['code']] = $data->$attribute['code']; 00066 } 00067 } 00068 00069 try { 00070 $link->getResource()->saveProductLinks($product, $links, $typeId); 00071 } catch (Exception $e) { 00072 $this->_fault('data_invalid', Mage::helper('catalog')->__('Link product not exists.')); 00073 } 00074 00075 return true; 00076 }
update | ( | $ | type, | |
$ | productId, | |||
$ | linkedProductId, | |||
$ | data = array() | |||
) |
Update product link association info
string | $type | |
int|string | $productId | |
int|string | $linkedProductId | |
array | $data |
Reimplemented from Mage_Catalog_Model_Product_Link_Api.
Definition at line 87 of file V2.php.
00088 { 00089 $typeId = $this->_getTypeId($type); 00090 00091 $product = $this->_initProduct($productId); 00092 00093 $link = $product->getLinkInstance() 00094 ->setLinkTypeId($typeId); 00095 00096 $collection = $this->_initCollection($link, $product); 00097 00098 $links = $this->_collectionToEditableArray($collection); 00099 00100 $idBySku = $product->getIdBySku($linkedProductId); 00101 if ($idBySku) { 00102 $linkedProductId = $idBySku; 00103 } 00104 00105 foreach ($collection->getLinkModel()->getAttributes() as $attribute) { 00106 if (isset($data->$attribute['code'])) { 00107 $links[(int)$linkedProductId][$attribute['code']] = $data->$attribute['code']; 00108 } 00109 } 00110 00111 try { 00112 $link->getResource()->saveProductLinks($product, $links, $typeId); 00113 } catch (Exception $e) { 00114 $this->_fault('data_invalid', Mage::helper('catalog')->__('Link product not exists.')); 00115 } 00116 00117 return true; 00118 }