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

Magento:將捆綁中的簡單產品添加到購物車中的單獨

Magento: Adding simple products from a bundle to separate lines in the cart(Magento:將捆綁中的簡單產品添加到購物車中的單獨行)
本文介紹了Magento:將捆綁中的簡單產品添加到購物車中的單獨行的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我的客戶要求在用戶添加時,將他們銷售的捆綁產品中的每個簡單產品(上衣和下衣)作為單獨的行項目添加到購物車中.誰能指導我如何做到這一點?我對 MVC 和 Zend 框架相當擅長,但我需要一些幫助來找到控制將捆綁產品添加到購物車的確切文件,或者另一種方法來單獨添加這些項目.請假設此服裝唯一可能的產品類型是捆綁產品類型.

My client is requesting that each simple product within a bundled product they are selling (Clothing Top and Bottom) be added as a separate line item in the cart whenever a user adds it. Can anyone direct me in how to accomplish this? I am fairly good with MVC and the Zend Framework, but I need a bit of help finding the exact files that control adding bundled products to the cart, or an alternate method for getting these items added separately. Please assume that the only possible product type for this clothing is the Bundled product type.

推薦答案

你需要一個觀察者:

    <checkout_cart_product_add_after>
        <observers>
            <reporting>
                <type>singleton</type>
                <class>Yourcompany_yourmodelname_Model_Observer</class>
                <method>onCartProductAdd</method>
            </reporting>
        </observers>
    </checkout_cart_product_add_after>

然后做觀察者:

class ourcompany_yourmodelname_Model_Observer extends Mage_Core_Model_Abstract
{
    /**
     * Binds to the checkout_cart_product_add_after Event and passes control to the helper function to process the quote
     *
     * @param Varien_Event_Observer $observer
     * @return void
     */
    public function onCartProductAdd($observer){
        $product = $observer->getProduct();
        $isProductBundle = ($product->getTypeId() == 'bundle');
        $items_to_add = array();
        $oTypeInstance = $oProduct->getTypeInstance(true);
        $aSelections = $oTypeInstance->getSelectionsCollection($aOptionIds, $product );
        $aOptions = $oTypeInstance->getOptionsByIds($aOptionIds, $product);
        $bundleOptions = $aOptions->appendSelections($aSelections, true);
        foreach ($bundleOptions as $bundleOption) {
            if ($bundleOption->getSelections()) {
                $bundleSelections = $bundleOption->getSelections();    
                foreach ($bundleSelections as $bundleSelection) {
                       $items_to_add[] = $bundleSelection.getID();

               }

            }
       }
       insertExtractedProducts($items_to_add);
    }

     /**
     * Add extracted products into quote
     *
     * @param array $items_to_add
      */
    public function insertExtractedProducts($items_to_add){
        /**@var $cart Mage_Checkout_Model_Cart**/
        $cart = Mage::helper('checkout/cart')->getCart();
        $ids_to_add = array();
        foreach($items_to_add as $item_to_be_added){
            $ids_to_add[] = $item_to_be_added->getProductId();
        }
        $cart->addProductsByIDs($ids_to_add);
        $cart->save();
        Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
        }
   }

只是一個簡單的示例,但可能會有所幫助.

Just a simple sample, but it might help.

捆綁產品在通過代碼使用時可能會很復雜,難以理解:這是一個示例圖像:

Bundled products can be complicated to understand, when working with it via code: Here is a sample image:

每個捆綁產品都有一對多的選項,最終將是要添加到購物車中捆綁產品的鏈接.

Each Bundled product, have one to many options, which in the end will be links to products to be added to the bundle in the Shopping Cart.

每個選項由一對多的選擇組成,這些選擇將是最終出現在購物車中的鏈接產品,位于此捆綁產品下.一個選擇,通常可以設置為默認值,并且已經在產品頁面上被選中.可以在此鏈接中找到有關如何創建和配置捆綁產品的更多信息,因為在本文檔中,我們將只討論它的編程方面.捆綁產品的顯示頁面將如下所示:

Each Option consists of one to many Selections, which will be the linked products that will end up in the Shopping cart, under this bundled product. One Selection, can typically be set as the default, and will already be selected on the product page. More information can be found at this link on how to create and configure bundled products, because in this document, we will only discuss the programming side of it. The bundled product’s display page, will look like this:

點擊添加到購物車"后,它在購物車中可能看起來像這樣:捆綁樣品

It could look like this in the shopping cart, once you clicked on "Add to Cart": Bundle Sample

Sample Shampoo
1 x Moisturiser-125ml $29.95
Default Conditioner
1 x Moisturiser-60g $99.95

當通過代碼查詢這個產品時,你像任何普通產品一樣加載它:

When interrogating this product through code, you load it like any normal product:

$oProduct->load($vProductId);

一旦加載完畢,您需要獲取一個產品類型實例,以便您可以加載該產品類型的選項.

Once it is loaded, you need to get a product type instance, so that you can load the options for this product type.

$oTypeInstance = $oProduct->getTypeInstance(true);

現在我們可以通過這種方式獲取此產品的選項 ID 列表:

Now we can get the list of option ID’s for this product in this manner:

$oTypeInstance = $oProduct->getTypeInstance(true);

為了查詢選擇,我們將選項列表添加到集合中,然后獲取選項集合,以及它們各自的選擇:

To interrogate the Selections, we will add the list of options to a collection, then get the Options collection, as well as their respective Selections:

$aSelections = $oTypeInstance->getSelectionsCollection($aOptionIds, $oProduct );
$aOptions = $oTypeInstance->getOptionsByIds($aOptionIds, $oProduct);
$bundleOptions = $aOptions->appendSelections($aSelections, true);

現在我們有一個選項集合,每個選項都有一個選擇集合.我們現在可以遍歷選項,并查看它們的選擇.

Now we have a Collection of Options, and each Option will have a collection of Selections. We can now loop through the options, and look at their Selctions.

foreach ($bundleOptions as $bundleOption) {
            if ($bundleOption->getSelections()) {
                $bundleSelections = $bundleOption->getSelections();

                foreach ($bundleSelections as $bundleSelection) {
                     // get some data here
                     $vName = $bundleOption->getTitle();
               }

            }
}

要獲取捆綁產品的必選產品列表,您可以使用以下代碼:

To get a list of the Required Selection Products for the Bundled product, you can use the following code:

$requiredChildren = $this->getChildrenIds($product->getId(),$required=true);

然后,您可以遍歷 ID 數組并按 ID 加載產品,以獲取有關這些產品的更多信息.

You can then loop through the array of ID’s and load the products by their ID’s to get more information regarding those products.

購物車中的捆綁產品

為了循環瀏覽購物卡中捆綁產品的選定選項,您可以使用以下內容:

In order to loop through the selected options of a Bundled product in the shopping card, you can use something like this:

/**
 * @var Mage_Bundle_Model_Product_Type
 */
$typeInstance = $this->getProduct()->getTypeInstance(true);

// get bundle options
$optionsQuoteItemOption =  $this->getItem()->getOptionByCode('bundle_option_ids');
$bundleOptionsIds = unserialize($optionsQuoteItemOption->getValue());
if ($bundleOptionsIds) {
    /**
    * @var Mage_Bundle_Model_Mysql4_Option_Collection
    */
    $optionsCollection = $typeInstance->getOptionsByIds($bundleOptionsIds, $this->getProduct());

    // get and add bundle selections collection
    $selectionsQuoteItemOption = $this->getItem()->getOptionByCode('bundle_selection_ids');

    $selectionsCollection = $typeInstance->getSelectionsByIds(
        unserialize($selectionsQuoteItemOption->getValue()),
        $this->getProduct()
    );

    $bundleOptions = $optionsCollection->appendSelections($selectionsCollection, true);
    foreach ($bundleOptions as $bundleOption) {
        if ($bundleOption->getSelections()) {
            $label = $bundleOption->getTitle()

            $bundleSelections = $bundleOption->getSelections();

            foreach ($bundleSelections as $bundleSelection) {                        
                    $sName = $bundleSelection->getName();
            }
            // some more code here to do stuff
        }
    }
}

此代碼從 Quote Item Bundled Product 中獲取 Options,然后在一個集合中獲取該產品的 Options,然后找到Selected"Option Selection.

This code gets the Options from the Quote Item Bundled Product, and then gets the Options for that product in a collection, and then finds the "Selected" Option Selection.

嗯,肖恩

這篇關于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)
主站蜘蛛池模板: 欧美九九 | 欧美一级片在线看 | 国产成人av一区二区三区 | 亚洲视频免费在线看 | 亚洲中午字幕 | 国产精品一区在线观看 | 在线观看视频中文字幕 | 91久久久久久久久久久 | 国产精品久久福利 | 天天干天天操天天看 | 国产在线视频一区二区董小宛性色 | 久久精品一 | 天天艹| 亚洲视频在线观看 | 久久久性色精品国产免费观看 | 亚洲一区二区精品视频在线观看 | jvid精品资源在线观看 | 蜜桃av鲁一鲁一鲁一鲁 | 91精品国产91久久久久久 | 色综久久 | 自拍偷拍亚洲视频 | 国产精品不卡 | 国产乱码精品一区二三赶尸艳谈 | 国产1区在线 | 久久久久久九九九九 | 欧美a级成人淫片免费看 | 精品粉嫩aⅴ一区二区三区四区 | 国产精品成人一区二区三区夜夜夜 | 欧美一区2区三区4区公司二百 | 午夜精品久久久久久不卡欧美一级 | 91在线视频播放 | 精品成人一区 | 成人高清视频在线观看 | 国外成人免费视频 | 成人午夜影院 | 99精品国自产在线 | 精品视频一区二区 | 国产www在线 | 中文字幕 在线观看 | 亚洲精品乱码久久久久久按摩 | 特黄视频|