Magento - 动态产品/动态定价/动态创建产品

Joh*_*aly 3 php magento

我多次使用magento,但这是最终的挑战.我正在一家拥有400,000多种产品的magento商店工作 - 每种产品都有自己的变化/产品选择.我们的主商店每天都会添加和删除数百种产品(基于自定义购物车系统并在MSSQL上运行).

我已配置magento以获取所有类别,产品,文本,描述,价格,变化等,并动态创建产品页面,例如http://www.offices-furniture.co.uk/pp?prod=mercury-接收unit.html

问题是我现在需要能够将这些产品添加到购物车中,而不会将它们实际存在于后端.我已经在后端添加了一个产品并计划将其用作GENERAL模板类型产品,因此它总是将此产品(其变体)添加到购物车中,例如

http://www.offices-furniture.co.uk/frodo.php但我不能为我的生活得到改变的价格.... grrrr ..

如果有人能指出我正确的方向如何通过前端的HTML或PHP更改价格并将其发布到购物车而不改变后端的价格

在此先感谢所有...

这是我尝试用来改变价格的代码;

    <?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{
?> 
Run Code Online (Sandbox Code Playgroud)

Mar*_*ust 5

这是一个可能会帮助你的片段......当产品被添加到购物车时,你肯定可以随时改变价格.我在checkout_cart_save_before事件观察者上使用它,在这个例子中,它在物品的重量超过10磅时触发.

/**
 * Set the price if the weight is over 10 lbs
 * 
 * @param Varien_Event_Observer $observer
 */
public function setPriceOnCartSaveBefore(Varien_Event_Observer $observer)
{
    $cart = $observer->getCart();
    $items = $cart->getItems();

    foreach($items as $item) {
        if ($item->getWeight() > 10) {
            $item->setCustomPrice(69.99);
            $item->setOriginalCustomPrice(69.99);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)