我用过很多次magento,但这是终极挑战。我在一家拥有超过 400,000 种产品的 magento 商店工作——每种产品都有自己的变体/产品选项。每天在我们的主商店(基于自定义购物车系统并在 MSSQL 上运行)上添加和删除数百种产品。
我已将 magento 配置为获取所有类别、产品、文本、描述、价格、变化等,并动态创建产品页面,例如http://www.offices-furniture.co.uk/pp?prod=mercury-接收单元.html
问题是我现在需要能够将这些产品添加到购物车中,而它们实际上并不存在于后端。我已将一种产品添加到后端并计划将其用作 GENERAL 模板类型的产品,因此始终将其添加到购物车中的该产品(它的变体),例如
http://www.offices-furniture.co.uk/frodo.php但我这辈子都无法改变价格...... grrrr ..
如果有人能指出我如何在前端通过 HTML 或 PHP 更改价格并将其发布到购物车而不更改后端价格的正确方向
在此先感谢大家...</p>
这是我尝试用来更改价格的代码;
<?php
require_once ("app/Mage.php");
umask(0);
Mage::app("default");
Mage::getSingleton("core/session", array("name" => "frontend"));
// get the current Magento cart
$cart = Mage::getSingleton('checkout/cart');
$product = Mage::getModel('catalog/product');
$product->setCustomPrice(99);
$product->setOriginalCustomPrice(99);
$product->getProduct()->setIsSuperMode(true);
$product->setTypeId('configurable');
$product->setTaxClassId(1); //none
$product->setSku(ereg_replace("\n","","videoTest2.2"));
$product->setName(ereg_replace("\n","","videoTest2.2"));
$product->setDescription("videoTest2.2");
$product->setPrice("129.95");
$product->setShortDescription(ereg_replace("\n","","videoTest2.2"));
$cart->save();
if(isset($_POST['submit'])){
// call the Magento catalog/product model
$product = Mage::getModel('catalog/product')
// set the current store ID
->setStoreId(Mage::app()->getStore()->getId())
// load the product object
->load($_POST['product']);
*/
////////////////////////////
// get the current Magento cart
$cart = Mage::getSingleton('checkout/cart');
$product = Mage::getModel('catalog/product')
// set the current store ID
->setStoreId(Mage::app()->getStore()->getId())
// load the product object
->load($_POST['product']);
$product->setCustomPrice(99);
$product->setOriginalCustomPrice(99);
$product->getProduct()->setIsSuperMode(true);
$product->setTypeId('configurable');
$product->setTaxClassId(1); //none
$product->setSku(ereg_replace("\n","","videoTest2.2"));
$product->setName(ereg_replace("\n","","videoTest2.2"));
$product->setDescription("videoTest2.2");
$product->setPrice("129.95");
$product->setShortDescription(ereg_replace("\n","","videoTest2.2"));
$cart->save();
/////////////////////////////////////
// start adding the product
// format: addProduct(<product id>, array(
// 'qty' => <quantity>,
// 'super_attribute' => array(<attribute id> => <option id>)
// )
// )
$cart->addProduct($product, array(
'qty' => $_POST['qty'],
'price' => 50,
'super_attribute' => array( key($_POST['super_attribute']) => $_POST['super_attribute'][525] )
)
);
// save the cart
$cart->save();
// very straightforward, set the cart as updated
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
// redirect to index.php
header("Location: frodo.php");
}else{
?>