我想在给定store_id和option_id相同时删除自定义选项。
目前磁力有此代码
foreach ($product->getOptions() as $option)
{
$option->getValueInstance()->deleteValue($option->getId());
$option->deletePrices($option->getId());
$option->deleteTitles($option->getId());
$option->delete();
}
我尝试使用此代码进行删除
foreach ($product->getOptions() as $option)
{
$allStores = Mage::app()->getStores();
foreach ($allStores as $_eachStoreId => $val)
{
if($_storeCode = Mage::app()->getStore($_eachStoreId)->getCode() == $importData['store'])
{
$option->getValueInstance()->deleteValue($option->getId());
$option->deletePrices($option->getId());
$option->deleteTitles($option->getId());
$option->delete();
}
}
}
但是当option_id
相同时它会删除所有自定义选项而不会检查store_id
所以请帮助我如何在特定的store_id和option_id?
时删除自定义选项答案 0 :(得分:1)
我改变了你的代码。它现在应该更快更好地工作。检查一下:
$allStores = Mage::app()->getStores(false,true);
foreach ($product->getOptions() as $option)
{
foreach ($allStores as $_eachStoreCode => $val)
{
if(strcasecmp($_eachStoreCode,$importData['store']) == 0)
{
$option->getValueInstance()->deleteValue($option->getId());
$option->deletePrices($option->getId());
$option->deleteTitles($option->getId());
$option->delete();
}
}
}
this link似乎也对您有所帮助。