由于某些原因,你可能需要在Magento视图文件中用自定义代码删除产品。但是你会惊讶的看到 “Cannot complete this operation from non-admin area.”这样的报错。下面有些小技巧让你实现它,这里是奏效的代码部分。
$_authors_product = new Mage_Catalog_Model_Product();
$_authors_product->load($_item_val_id);
//echo "DELETED... ".$_POST['submit_item4sale_remove_by_entity_id'];
$_item_val_id = $_POST['submit_item4sale_remove_by_entity_id'];
$_item_val_id = (int)str_replace('entity_id_', '', $_item_val_id);
$_authors_product = new Mage_Catalog_Model_Product();
$_authors_product->load($_item_val_id);
$_current_customer_id = Mage::getSingleton('customer/session')->getCustomer()->getId();
//Allow deletion only if product is from author
if($_authors_product->submited_by_author == $_current_customer_id)
{
//var_dump(Mage::registry('isSecureArea'));
Mage::register('isSecureArea', true);
//$_authors_product->delete();
echo 'ALLOWED DELETED OH YEAAAAAA....';
Mage::unregister('isSecureArea');
}
其中最重要的是:
Mage::register('isSecureArea', true);
echo 'ALLOWED DELETED OH YEAAAAAA....';
Mage::unregister('isSecureArea');
基本的想法是在注册表中写入合适的值Mage::register(‘isSecureArea’, true),删除产品后移除它。 (责任编辑:最模板) |

dedecms网络公司sincer网站模
人气:490
仿万家购物网 购物返利网
人气:4560
ecshop仿唯伊网模板|化妆品
人气:1710
zencart鞋类模板
人气:2895
ecshop仿西米零食网模板
人气:1041
AZ Shop多用途外贸商城mag
人气:223