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

將選項值添加到產品,然后使用 Magento 添加到購

Add option value to product, then to cart with Magento(將選項值添加到產品,然后使用 Magento 添加到購物車)
本文介紹了將選項值添加到產品,然后使用 Magento 添加到購物車的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我搜索了一段時間,只找到了為 Magento 商店中的產品添加全新選項集的機智解決方案.

I searched around for a while and only came up wit solutions that added whole new option sets to products in a Magento store.

我想要完成的是一種將簡單產品添加到購物車的方法.這個簡單的產品有一些預定義的自定義選項(自由文本字段),必須由 php 函數填充.

What I'm trying to accomplish is a way to add a Simple Product to the cart. This Simple Product has some predifined custom options (free text fields) that has to be filled by a php function.

那么,我該怎么做呢?假設我有一個 ID 為111"的產品和一個自定義選項.

So, how can I do this? Let's say I have a product with the ID "111" and a one custom option.

$qty = '1';
$product = Mage::getModel('catalog/product')->load("111");
// set option value in product model?

$cart = Mage::helper('checkout/cart')->getCart();
$cart->addProduct($product, $qty);
// set option value while passing product to car?

$cart->save();

提前感謝您的幫助.

順便說一句:通過 QueryString 設置選項值相對容易,如此處所示.

BTW: setting option values via QueryString is relativly easy as seen here.

推薦答案

您沒有在產品模型上設置自定義選項,而是通過第二個參數將其傳遞給 $cart->addProduct($產品,$params).

You don't set the custom option on the product model, you pass it in through the second argument to $cart->addProduct($product, $params).

我們為一個需要外部應用程序添加到 Magento 購物車的項目進行的設置是使用以下格式的 $params 數組:

The set up we have for a project, that requires an external app to add to the Magento cart, is to use a $params array of the following format:

$params = array(
    'product' => 1, // This would be $product->getId()
    'qty' => 1,
    'options' => array(
        34 => "value",
        35 => "other value",
        53 => "some other value"
    )
);

$params['options'] 包含自定義選項信息.鍵是自定義選項 ID,如果您使用 Firebug 或類似工具檢查產品屏幕的自定義選項部分,您可以看到它們.

The $params['options'] contains the custom option information. The keys are the custom option ids, you can see them if you inspect the custom options section of the product screen with Firebug, or similar.

$params['product'] 可能是多余的,我不久前為 Magento 的早期版本編寫了這個腳本.

The $params['product'] may be redundant, I wrote this script a while ago for a much earlier version of Magento.

另外,我相當確定,當您以這種方式添加時,標準的添加到購物車 事件會觸發,因此您需要自己設置它們.可能會有副作用.

Also, I'm fairly sure that the standard add to cart events will fire when you add this way, so you'll need to set them off yourself. There may be side effects.

這篇關于將選項值添加到產品,然后使用 Magento 添加到購物車的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
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 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 午夜精品在线 | 久草a√| 青青草视频网站 | 欧美精品综合 | 亚洲精久久久 | 一区二区福利视频 | 91视频国产区 | 亚洲色图第一页 | 国产精品一区一区三区 | 久久亚洲天堂 | 在线欧美小视频 | 午夜国产一级片 | 日韩免费一区二区 | 9久久精品 | 在线观看成人免费视频 | 999久久精品 | 美女黄频 | 日韩精品一区二区三区在线观看 | 午夜视频免费在线观看 | 久久久毛片 | 欧美三级三级三级爽爽爽 | 青青草综合网 | 国产农村妇女精品一二区 | 日韩视频精品在线 | 一级片在线播放 | 亚洲国产精品日韩av不卡在线 | 日韩免费高清视频 | 色黄视频在线 | 精品1区2区 | 我爱操| 男女羞羞在线观看 | 亚洲精品久久久一区二区三区 | 91精品国产欧美一区二区成人 | www日本高清| 国产精品黄 | av网站在线看| 欧美精品一区二区三区在线播放 | 国产一区二区久久久 | 天天影视亚洲综合网 | 在线观看视频福利 | 国产欧美一区二区三区日本久久久 |