Skip to content
This repository has been archived by the owner on Jun 10, 2019. It is now read-only.

More changes found with updated regex #21

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions app/code/local/Inchoo/PHP7/Model/Product/Link/Api/V2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
/**
* Created on: 2016-03-02
* @copyright Inchoo d.o.o. (http://inchoo.net)
* @author Benjam Welker
* @license MIT
*/
class Inchoo_PHP7_Model_Product_Link_Api_V2 extends Mage_ImportExport_Model__Product_Link_Api_V2
{

public function assign($type, $productId, $linkedProductId, $data = array(), $identifierType = null)
{
$typeId = $this->_getTypeId($type);

$product = $this->_initProduct($productId, $identifierType);

$link = $product->getLinkInstance()
->setLinkTypeId($typeId);

$collection = $this->_initCollection($link, $product);
$idBySku = $product->getIdBySku($linkedProductId);
if ($idBySku) {
$linkedProductId = $idBySku;
}

$links = $this->_collectionToEditableArray($collection);

$links[(int) $linkedProductId] = array();
foreach ($collection->getLinkModel()->getAttributes() as $attribute) {
if (isset($data->{$attribute['code']})) {
$links[(int) $linkedProductId][$attribute['code']] = $data->{$attribute['code']};
}
}

try {
if ($type == 'grouped') {
$link->getResource()->saveGroupedLinks($product, $links, $typeId);
} else {
$link->getResource()->saveProductLinks($product, $links, $typeId);
}

$_linkInstance = Mage::getSingleton('catalog/product_link');
$_linkInstance->saveProductRelations($product);

$indexerStock = Mage::getModel('cataloginventory/stock_status');
$indexerStock->updateStatus($productId);

$indexerPrice = Mage::getResourceModel('catalog/product_indexer_price');
$indexerPrice->reindexProductIds($productId);

} catch (Exception $e) {
$this->_fault('data_invalid', $e->getMessage());
//$this->_fault('data_invalid', Mage::helper('catalog')->__('Link product does not exist.'));
}

return true;
}

public function update($type, $productId, $linkedProductId, $data = array(), $identifierType = null)
{
$typeId = $this->_getTypeId($type);

$product = $this->_initProduct($productId, $identifierType);

$link = $product->getLinkInstance()
->setLinkTypeId($typeId);

$collection = $this->_initCollection($link, $product);

$links = $this->_collectionToEditableArray($collection);

$idBySku = $product->getIdBySku($linkedProductId);
if ($idBySku) {
$linkedProductId = $idBySku;
}

foreach ($collection->getLinkModel()->getAttributes() as $attribute) {
if (isset($data->{$attribute['code']})) {
$links[(int) $linkedProductId][$attribute['code']] = $data->{$attribute['code']};
}
}

try {
if ($type == 'grouped') {
$link->getResource()->saveGroupedLinks($product, $links, $typeId);
} else {
$link->getResource()->saveProductLinks($product, $links, $typeId);
}

$_linkInstance = Mage::getSingleton('catalog/product_link');
$_linkInstance->saveProductRelations($product);

$indexerStock = Mage::getModel('cataloginventory/stock_status');
$indexerStock->updateStatus($productId);

$indexerPrice = Mage::getResourceModel('catalog/product_indexer_price');
$indexerPrice->reindexProductIds($productId);

} catch (Exception $e) {
$this->_fault('data_invalid', Mage::helper('catalog')->__('Link product does not exist.'));
}

return true;
}

}
9 changes: 7 additions & 2 deletions app/code/local/Inchoo/PHP7/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</totals>
</quote>
</sales>

<models>
<inchoo_php7>
<class>Inchoo_PHP7_Model</class>
Expand All @@ -41,6 +41,11 @@
<export_entity_customer>Inchoo_PHP7_Model_Export_Entity_Customer</export_entity_customer>
</rewrite>
</importexport>
<catalog>
<rewrite>
<product_link_api_v2>Inchoo_PHP7_Model_Product_Link_Api_V2</product_link_api_v2>
</rewrite>
</catalog>
</models>
</global>
</config>
</config>
Loading