2013-03-26 153 views
3

我試圖讓我的Upsell產品,我使用而不是相關的產品上的view.phtml,與數量字段前面的工作添加到購物車按鈕。我也使用AheadWorks Ajax AddToCart Pro 2.5擴展。Magento - 添加到購物車的數量字段Upsell產品

眼下,我'加入產品無數量字段在這個片段:

<form action="<?php echo $this->getAddToCartUrl($_link) ?>" method="post" id="view_addtocart_form_<?php echo $_link->getId(); ?>"><button onclick="setLocation('<?php echo $this->getAddToCartUrl($_link) ?>')" class="greenbutton" title="Add to Cart" type="button"><span><span>Add to Cart</span></span></button></form> 

這個偉大的工程,但我不能在數量變化,由於缺乏量場。然後,我嘗試使用這個從我list.phtml的正常工作,在分類視圖:

<script type="text/javascript"> 
        function setQty(id, url) { 
         var qty = document.getElementById('qty_' + id).value; 
         document.getElementById('cart_button_' + id).innerHTML = '<button type="button" class="greenbutton-small" onclick="setLocation(\'' + url + 'qty/' + qty + '/\')"><span><span>Læg i kurv</span></span></button>'; 
        } 
       </script> 
       <label for="qty"><?php echo $this->__('Qty:') ?></label> 
       <input type="text" name="qty_<?php echo $_product->getId(); ?>" id="qty_<?php echo $_product->getId(); ?>" maxlength="12" value="1" onkeyup="setQty(<?php echo $_product->getId(); ?>, '<?php echo $this->getAddToCartUrl($_product) ?>');" title="<?php echo $this->__('Qty') ?>" class="input-text qty" /> 
       <span id="cart_button_<?php echo $_product->getId(); ?>"> 
       <button type="button" class="greenbutton-small" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></span>  

現在,有趣的是,如果我嘗試在upsell.phtml使用它,這並不工作,但我無法弄清楚爲什麼?這可以在類別視圖的AW中使用Ajax Cart Pro完美實現。

回答

3

upsell.phtml產品對象被稱爲$_link每下面的代碼:

<?php if($_link=$this->getIterableItem()): ?> 

如果你想在您的upsell.phtml你的代碼,那麼你就必須改變$_product$_link這樣的:

<label for="qty"><?php echo $this->__('Qty:') ?></label> 
      <input type="text" name="qty_<?php echo $_link->getId(); ?>" id="qty_<?php echo $_link->getId(); ?>" maxlength="12" value="1" onkeyup="setQty(<?php echo $_link->getId(); ?>, '<?php echo $this->getAddToCartUrl($_link) ?>');" title="<?php echo $this->__('Qty') ?>" class="input-text qty" /> 
      <span id="cart_button_<?php echo $_link->getId(); ?>"> 
      <button type="button" class="greenbutton-small" onclick="setLocation('<?php echo $this->getAddToCartUrl($_link) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></span> 

應該在以下行的後面去:

<?php if($_link=$this->getIterableItem()): ?> 
+0

你值得擁抱..從某人熱! ;) 呵呵。這真的拯救了我的一天。非常感謝,這麼一件小事,甚至都沒有想過。非常感謝你。 – 2013-03-26 18:30:47

相關問題