久久久久久久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)
主站蜘蛛池模板: 一区二区三区四区在线播放 | h片在线观看免费 | av毛片| 九九免费视频 | 日韩av在线一区二区 | 成人免费网视频 | 午夜激情网| 亚洲视频 欧美视频 | 中文字幕av一区二区三区 | 蜜桃传媒一区二区 | 日本精品一区二区三区视频 | 波波电影院一区二区三区 | 日韩国产精品一区二区三区 | 久久亚洲一区二区 | 亚洲国产aⅴ成人精品无吗 综合国产在线 | 亚洲一区二区三区在线视频 | 精产国产伦理一二三区 | 精品欧美一区二区精品久久久 | 免费小视频在线观看 | 精品精品视频 | 天天干 夜夜操 | 国产精品久久久久av | 一区二区在线 | 久久久久久国产精品 | 91国内在线观看 | 日韩中出 | 色爱综合网| 国产精品视频久久久久久 | 蜜桃在线视频 | 成人黄色电影在线播放 | 国产91在线 | 中日 | 亚洲欧美中文日韩在线v日本 | 免费观看a级毛片在线播放 黄网站免费入口 | 天天干天天爽 | 欧美日韩在线一区二区 | 黄色毛片在线观看 | 日韩免费看视频 | 久久久久亚洲精品国产 | 狠狠做六月爱婷婷综合aⅴ 国产精品视频网 | 91视频进入 | 中文字幕免费 |