2016-06-09 62 views
0

我有一個關於直接從交叉銷售部分向購物車頁面上的購物車添加可配置產品的問題。使用簡單的產品,這不是問題,因爲它沒有屬性。但對於可配置產品,通常我必須通過下拉列表選擇我想要的產品(如尺寸或顏色)。如果我選擇可配置的產品作爲交叉銷售,並且點擊「加入購物車」 - 按鈕,它會將我重定向到產品詳細信息頁面。Magento 1.9 - 從購物車的croll-sells直接添加可配置產品到購物車

所以這個想法是有一個像彈出的東西,我可以直接選擇大小和顏色,並將產品(具有選定的屬性)添加到購物車。

是否有一個模塊帶來的功能(我找不到)?還是我可以像我每個交叉銷售的表格一樣自己寫一些東西?

喜歡該產品的詳細信息頁面

<form action="<?php echo $this->getSubmitUrl($_product, array('_secure' => $this->_isSecure())) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>> 
    <?php echo $this->getBlockHtml('formkey') ?> 
    <div class="no-display"> 
     <input type="hidden" name="product" value="<?php echo $_product->getId() ?>" /> 
     <input type="hidden" name="related_product" id="related-products-field" value="" /> 
    </div> 
... 
+1

搜索的Magento的快速視圖模塊。將可配置產品添加到購物車時,它會彈出一個窗口。檢查代碼並嘗試。另外,請記住MD_QuickView模塊有一個SQL注入漏洞。 [示例搜索](https://www.magentocommerce.com/magento-connect/catalogsearch/result/?id=&s=7&pl=0&eb=0&hp=0&q=quickview&t=1&p=1) – aki

+0

不錯。感謝您分享鏈接。 –

回答

1

請仔細閱讀該代碼,希望這對代碼的形式有一個解決辦法。 ?

foreach ($_productCollection as $_product) { 

    ?> 
    <div class="sqs-col-4 item-product"> 
     <div class="thumb"><a href="<?php echo $_product->getProductUrl(); ?>" title="<?php echo $_product->getName(); ?>"><img src="<?php echo $_product->getImageUrl(); ?>" alt="" /></a></div> 
     <h1><a href="<?php echo $_product->getProductUrl(); ?>" title="<?php echo $_product->getName(); ?>"><?php echo $_product->getName(); ?></a></h1> 
     <h4><?php echo Mage::helper('core')->currency($_product->getPrice()); ?></h4> 

     <form action="<?php echo $this->helper('checkout/cart')->getAddUrl($_product);?>" method="post" id="product_addtocart_form"> 

     <?php 
      if ($_product->getData('type_id') == "configurable") 
      { 
       //get the configurable data from the product 
       $config = $_product->getTypeInstance(true); 
       //loop through the attributes 

       foreach($config->getConfigurableAttributesAsArray($_product) as $attributes) 
       { 

        ?> 
        <div id="product-options-wrapper" class="select_number"> 
         <label class="required last"><em>*</em><?php echo $attributes["frontend_label"]; ?></label> 
          <select class="required-entry" name="super_attribute[<?php echo $attributes['attribute_id'] ?>]" id="attribute<?php echo $attributes['attribute_id'] ?>"> 
            <option value=""><?php echo $attributes["store_label"]; ?></option> 
            <?php 

            foreach($attributes["values"] as $values) 
            { 
             echo "<option value=".$values["value_index"].">".$values["label"]."</option>"; 
            } 
            ?> 
          </select> 
        </div> 
        <div style="display: none;" id="advice-required-entry-attribute<?php echo $attributes['attribute_id'] ?>" class="validation-advice">This is a required field.</div> 
        <?php 
       } 
      } 
     if(!$_product->isGrouped()): ?> 
     <label for="qty"><?php echo $this->__('Quantity') ?>:</label> 
     <input type="number" name="qty" id="qty" maxlength="3" value="<?php echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>"/> 
     <?php endif; ?> 

     <?php if($_product->isSaleable()): ?> 
      <button type="button" id="" title="<?php echo $this->__('Add to Cart') ?>" onclick="productAddToCartForm.submit(this)" value="Add To cart" /></button> 
     <?php else: ?> 
      <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p> 
     <?php endif; ?> 
    </form> 
    </div> 
    <?php  
} 

>

添加也是這個腳本:

<script> 
var productAddToCartForm = new VarienForm('product_addtocart_form'); 

     productAddToCartForm.submit = function(button, url) { 
      if (this.validator.validate()) { 
       var form = this.form; 
       var oldUrl = form.action; 

       if (url) { 
        form.action = url; 
       } 
       var e = null; 
       try { 
        this.form.submit(); 
       } catch (e) { 
       } 
       this.form.action = oldUrl; 
       if (e) { 
        throw e; 
       } 

       if (button && button != 'undefined') { 
        button.disabled = true; 
       } 
      } 
     }.bind(productAddToCartForm); 

相關問題