我正在尝试从前端更新产品,但它不允许我更新产品的所有字段,
以下是索引控制器的代码 FOR UPDATING :
public function updateVproductAction(){
if($addvp = $this->getRequest()->getPost())
{
/*********************** Product Update ***************************/
/**
* Get the resource model
*/
$resource = Mage::getSingleton('core/resource');
/**
* Retrieve the write connection
*/
$writeConnection = $resource->getConnection('core_write');
/**
* Retrieve our table name
*/
$table = $resource->getTableName('catalog/product');
/**
* Set the product ID
*/
$productId = $addvp['product']['id'];
/**
* Set the new SKU
* It is assumed that you are hard coding the new SKU in
* If the input is not dynamic, consider using the
* Varien_Db_Select object to insert data
*/
//$newSku = 'new-sku';
$sku = $addvp['product']['sku'];
$name = $addvp['product']['name'];
$description = $addvp['product']['description'];
$short_description = $addvp['product']['short_description'];
$weight = $addvp['product']['weight'];
$news_from_date = $addvp['product']['news_from_date'];
$news_to_date = $addvp['product']['news_to_date'];
$status = $addvp['product']['status'];
$price = $addvp['product']['price'];
$special_price = $addvp['product']['special_price'];
$tax_class_id = $addvp['product']['tax_class_id'];
$meta_title = $addvp['product']['meta_title'];
$meta_keyword = $addvp['product']['meta_keyword'];
$meta_description = $addvp['product']['meta_description'];
$stock_data = array(
'is_in_stock' => 1,
'qty' => $addvp['product']['stock_data']['qty']
);
$query = "UPDATE {$table} SET sku = '{$sku}', name = '{$name}', description = '{$description}', short_description = '{$short_description}', weight = '{$weight}', news_from_date = '{$news_from_date}', news_to_date = '{$news_to_date}', status = '{$status}', price = '{$price}', special_price = '{$special_price}', tax_class_id = '{$tax_class_id}', meta_title = '{$meta_title}', meta_keyword = '{$meta_keyword}', meta_description = '{$meta_description}', stock_data = '{$stock_data}' WHERE entity_id = "
.(int) $productId;
try
{
/**
* Execute the query
*/
$writeConnection->query($query);
echo "successfully updated product with ID: ". $productId ."<br />";
}
catch (Exception $e)
{
echo "Could not update product with ID: ". $productId ."<br />";
}
}
}
任何人都可以帮助并纠正我错在哪里吗?
对于删除产品,我只是从Helper调用此功能:
public function vDeleteproduct($vprod){
//print_r($vprod); exit;
try
{
$product = Mage::getSingleton('catalog/product')->load($vprod);
Mage::dispatchEvent('catalog_controller_product_delete', array('product' => $product));
$product->delete();
//$product = Mage::getModel('catalog/product')->load($vprod)->delete();
echo "successfully deleted product with ID: ". $vprod ."<br />";
}
catch (Exception $e)
{
echo "Could not delete product with ID: ". $vprod ."<br />";
}
return;
}
它也不起作用:(
Plz帮助。
答案 0 :(得分:1)
删除产品:
我通过仅从非管理区域(即前端)访问删除来找到答案。它为我带来了魔力。
以上链接帮助我找到解决方案。