Created
September 24, 2015 17:16
-
-
Save jonatanrdsantos/92b49f2358c23db51a18 to your computer and use it in GitHub Desktop.
Magento Update Options
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(E_ALL); | |
require_once '../../../../../Mage.php'; | |
Mage::app(); | |
require_once './Garantia.php'; | |
$productModel = Mage::getModel('catalog/product'); | |
//Get Product Collection | |
$collection = Mage::getModel('catalog/product')->getCollection(); | |
$teste = "select count(prod.sku) as soma,prod.entity_id, prod.sku, op.option_id, opt.title, optt.title | |
from catalog_product_entity as prod | |
INNER JOIN catalog_product_option as op | |
ON op.product_id = prod.entity_id | |
LEFT JOIN catalog_product_option_title as opt | |
ON opt.option_id = op.option_id | |
LEFT JOIN catalog_product_option_type_value as optv | |
ON optv.option_id = op.option_id | |
LEFT JOIN catalog_product_option_type_title as optt | |
ON optt.option_type_id = optv.option_type_id | |
Where prod.has_options = 1 | |
AND prod.entity_id = 35132 OR prod.entity_id = 35074 | |
GROUP BY prod.sku,optt.title | |
LIMIT 5000 | |
"; | |
$connection = Mage::getSingleton('core/resource')->getConnection('core_read'); | |
$rows = $connection->fetchAll($teste); | |
$sampleOptions = array(); | |
foreach ($rows as $row){ | |
if(isset($row['soma']) | |
&& $row['soma'] > 1) | |
{ | |
//duplicado | |
$product = Mage::getModel('catalog/product')->load($row['entity_id']); | |
_deleteProduct($product); | |
}else{ | |
//unico | |
} | |
} | |
function _deleteProduct($product){ | |
$options = $product->getOptions(); | |
foreach($option as $option){ | |
$optionsData = $option->getData(); | |
$optionsData['is_delete'] = 1; | |
$product->setProductOptions(array($option->getId() => $optionsData)); | |
$product->setCanSaveCustomOptions(true); | |
$product->save(); | |
} | |
} | |
function _updateProduct($product){ | |
} | |
public function getOptions($data,$skuFilter){ | |
$returnData = array(); | |
$returnUpdate = array(); | |
$newData = $this->getFilterOptions($data,$skuFilter); | |
foreach($newData as $dados){ | |
$returnData[] = array( | |
'title' => $dados['description'], | |
'price' =>$dados['price'], | |
'price_type' => 'fixed', | |
'sku' => $dados['sku'], | |
'sort_order' => '0' | |
); | |
$returnUpdate[] = $dados['sku']; | |
} | |
return array('returnData' => $returnData, 'returnUpdate' => $returnUpdate); | |
} | |
public function getFilterOptions($data,$skuFilter) | |
{ | |
$returnDataFilter = array(); | |
foreach($data as $dados){ | |
if($dados['sku_reference'] == $skuFilter){ | |
$returnDataFilter[] = $dados; | |
} | |
} | |
return $returnDataFilter; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment