久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

magento 1.8 使用 php 將產(chǎn)品添加到購(gòu)物車

magento 1.8 add product to cart using php(magento 1.8 使用 php 將產(chǎn)品添加到購(gòu)物車)
本文介紹了magento 1.8 使用 php 將產(chǎn)品添加到購(gòu)物車的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

在 Magento 1.7 之前,我能夠使用以下代碼以編程方式將產(chǎn)品添加到購(gòu)物車:

Up until Magento 1.7 I was able to use the following code to add a product to cart programatically:

require_once '../app/Mage.php'; 
Mage::getSingleton('core/session', array('name' => 'frontend')); 
umask(0);  
Mage::app();  
$session = Mage::getSingleton('customer/session');  
$product = Mage::getModel('catalog/product')->load(99);  // Random product ID

// get cart and add product
$cart = Mage::getSingleton('checkout/cart'); 
$cart->init();
$cart->addProduct($product, 1);

// update session
$session->setCartWasUpdated(true);

// save the cart
$cart->save();  

然而,這在 Magento 1.8 中不再起作用.我一整天都在嘗試/搜索為什么會(huì)這樣.可悲的是,我還沒(méi)有找到有關(guān)此問(wèn)題的任何線索.

However, this does not work anymore in Magento 1.8. I've been trying/searching all day why this is the case. Sadly I haven't found any clue regarding this issue.

可能與1.8的變化有關(guān),這也導(dǎo)致使用URL方法時(shí)需要form-key;不過(guò),這是一個(gè)瘋狂的猜測(cè).

It may have to do with the changes in 1.8 which also causes the requirement for a form-key when using the URL method; this is a wild guess though.

在使用 Magento 1.8 時(shí),有人知道如何做到這一點(diǎn)嗎?

Anyone any idea or a working example on how to do this when working with Magento 1.8?

推薦答案

重新審視它并立即讓它運(yùn)行良好.僅供任何人參考,這是我正在使用的代碼(Magento 1.8):

Had a fresh look at it and got it working nicely right away. Just for anyone's reference, here's the code I'm using (Magento 1.8):

// Mage init
require_once '../../app/Mage.php'; 
umask(0);  
Mage::init('default');
Mage::getSingleton('core/session', array('name' => 'frontend'));  

// Get customer session
$session = Mage::getSingleton('customer/session'); 

// Get cart instance
$cart = Mage::getSingleton('checkout/cart'); 
$cart->init();

// Add a product (simple); id:12,  qty: 3 
$cart->addProduct(12, 3);

// Add a product with custom options
$productInstance = Mage::getModel('catalog/product')->load($productId);
$param = array(
    'product' => $productInstance->getId(),
    'qty' => 1,
    'options' => array(
        234 => 'A value'  // Custom option with id: 234
    )
);
$request = new Varien_Object();
$request->setData($param);
$cart->addProduct($productInstance, $request);

// Set shipping method
$quote = $cart->getQuote();
$shippingAddress = $quote->getShippingAddress();
$shippingAddress->setShippingMethod('flatrate_flatrate')->save();               

// update session
$session->setCartWasUpdated(true);

// save the cart
$cart->save(); 

這篇關(guān)于magento 1.8 使用 php 將產(chǎn)品添加到購(gòu)物車的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個(gè)表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設(shè)置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數(shù)組自動(dòng)填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產(chǎn)生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 在线日韩中文字幕 | 夜夜爽夜夜操 | 久久最新| 国产欧美日韩综合精品一区二区 | 日本在线免费观看 | 中文字幕国产 | 日韩精品一区二区在线 | 97综合在线 | 久一久| 日日碰狠狠躁久久躁96avv | 99热都是精品 | 欧美日韩国产高清视频 | 99re在线视频 | 亚洲成人福利 | 911精品国产 | 日本黄色一级片视频 | xx视频在线 | 精品一区二区三区四区在线 | 久久大| 伊人久久大香线 | 国产日产精品一区二区三区四区 | 日韩色视频 | 国产目拍亚洲精品99久久精品 | 国产乱码精品一品二品 | 一级做受毛片免费大片 | 久久免费视频在线 | 免费观看的黄色网址 | 中文字幕一区二区三区四区五区 | 国产精品免费小视频 | 成人在线免费电影 | 亚洲精品久久久久久一区二区 | 久久aⅴ乱码一区二区三区 亚洲国产成人精品久久久国产成人一区 | 一区二区三区四区电影视频在线观看 | 欧美成人a∨高清免费观看 色999日韩 | 久久黄色 | 欧美日韩一区二区三区在线观看 | 久久精品国产亚洲一区二区 | 伊人狠狠干 | 欧洲精品码一区二区三区免费看 | 狠狠影院 | av电影手机在线看 |