2012-12-19 103 views
0

我正在使用CMS頁面顯示一個主要產品和一系列配件。我遇到的問題是,當我從配件部分將產品添加到購物車時,它不會被添加。主要產品被添加到購物車中。將產品添加到購物車從CMS只提交一個產品系列

我已經設法把隔離問題的插件形成了主要產品:

<?php 
    $_product = $this->getProduct(); 
    $_helper = $this->helper('catalog/output'); 
?> 
<div class="pull-right"> 
<form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?> class="form"> 
<h2 class="product-name"><?php echo $this->__('Price:'); ?> <?php echo Mage::helper('core')->currency($_product->getPrice());; ?></h2> 
     <?php if($_product->isSaleable()): ?> 
    <p class="product-name"><?php echo $this->__('Quantity:'); ?></p>  
    <select name="qty" class="span1"> 
    <?php $i = 1 ?> 
    <?php do { ?> 
    <option value="<?php echo $i?>"> 
     <?php echo $i?> 
     <?php $i++ ?> 
    </option> 
    <?php } while ($i <= (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getMaxSaleQty()) ?> 
</select> 
      <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="btn btn-danger" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button> 
       <?php else: ?> 
      <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p> 
     <?php endif; ?> 
</form></div> 
<script type="text/javascript"> 
    //<![CDATA[ 
     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); 

     productAddToCartForm.submitLight = function(button, url){ 
      if(this.validator) { 
       var nv = Validation.methods; 
       delete Validation.methods['required-entry']; 
       delete Validation.methods['validate-one-required']; 
       delete Validation.methods['validate-one-required-by-name']; 
       if (this.validator.validate()) { 
        if (url) { 
         this.form.action = url; 
        } 
        this.form.submit(); 
       } 
       Object.extend(Validation.methods, nv); 
      } 
     }.bind(productAddToCartForm); 
    //]]> 
    </script> 

下面是配件的代碼 - 提交表單與上面:

<?php 
$category_id = "49"; // category_id for "Accessories" 
$_productCollection = Mage::getResourceModel('catalog/product_collection') 
->addAttributeToSelect(array('name', 'price', 'small_image', 'short_description'), 'inner') 
->addCategoryFilter(Mage::getModel('catalog/category')->load($category_id)); 
?> 
<?php if($_productCollection->count()): ?> 

     <?php 
     $products = array(); 
     foreach ($_productCollection as $_product) { 
     ?> 
<form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?> class="form"> 
    <div class="media"> 
      <a class="fancybox static-thumbs pull-left" href="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(500, 450); ?>" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>"> 
      <img class="media-object" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(150, 125); ?>" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" /> 
      </a> 
    <div class="media-body span6"> 
     <h4 class="media-heading"><a class="view-item-button" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->__('Order'); ?> <?php echo $this->htmlEscape($_product->getName())?><?php echo $this->__('&#8482;'); ?></a></h4> 

     <p> 
      <?php echo $_product->_data['short_description']; ?> 
     </p> 
     </div> 
     </div> 
     <div class="media pull-right"> 
     <h2 class="product-name"><?php echo $this->__('Price:'); ?> <?php echo Mage::helper('core')->currency($_product->getPrice()); ?></h2><?php if($_product->isSaleable()): ?> 

    <p class="product-name"><?php echo $this->__('Quantity:'); ?></p> 
    <select name="qty" class="span1"> 
    <?php $i = 1 ?> 
    <?php do { ?> 
    <option value="<?php echo $i?>"> 
     <?php echo $i?> 
     <?php $i++ ?> 
    </option> 
    <?php } while ($i <= (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getMaxSaleQty()) ?> 
</select> 

      <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="btn btn-danger" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button> 
       <?php else: ?> 
      <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p> 
     <?php endif; ?> 
     <?php } ?> 

    </div></form> 

<?php endif; ?> 
<hr /> 
<script type="text/javascript"> 
    $j(document).ready(function() { 
     $j(".fancybox").fancybox(); 
    }); 
</script> 

<script type="text/javascript"> 
    //<![CDATA[ 
     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); 

     productAddToCartForm.submitLight = function(button, url){ 
      if(this.validator) { 
       var nv = Validation.methods; 
       delete Validation.methods['required-entry']; 
       delete Validation.methods['validate-one-required']; 
       delete Validation.methods['validate-one-required-by-name']; 
       if (this.validator.validate()) { 
        if (url) { 
         this.form.action = url; 
        } 
        this.form.submit(); 
       } 
       Object.extend(Validation.methods, nv); 
      } 
     }.bind(productAddToCartForm); 
    //]]> 
    </script> 

如果我刪除表格,主要產品添加到購物車表格配件添加成功。我不知道如何調試,並可以做一些建議,請!!?

+0

我想我需要爲主要產品指定一個product_id ... – user1704524

+0

如果我從主產品中刪除表單,我可以添加到購物車,但一次只能添加一個,即使選擇了多個該產品! ? – user1704524

回答

0

不得不求助於使用立即訂購按鈕,將客戶帶到產品查看頁面。這意味着他們也可以在該頁面上配置產品!

相關問題