2013-01-09 48 views
0

首先:我得到了magento的mvc和php,但我對它的「內置功能」可能做的不完全熟悉。什麼是限制購買magento中可下載產品數量的好方法

我正在努力將用戶選擇我的書配置產品之一作爲epub或pdf版本的數量限制爲1。如果選擇不是「Physical」,我準備開始在主題中使用一些jQuery voodoo來解決它,以隱藏QTY選項。我希望有人可能知道一種方法來做到這一點,或者有經驗做過。

隨意用「這樣做是管理員」或「代碼是這樣的」

感謝

回答

3

您可以限制通過編輯並打算在車允許用於特定項目的項目數回答到「庫存」選項卡。有兩種設置:「購物車中允許的最小數量」和「購物車中允許的最大數量」。取消選中「使用配置設置」作爲「允許的最大數量」並將其設置爲1。

默認情況下,它們都是「使用配置」,這意味着它也可以在系統 - >配置 - >清單選項卡中編輯。

+0

很好的答案。我應該早點回來。我寫了jquery。我可以切換到這種方法。我所有的產品都使用肥皂調用進口。 – CarComp

0

如何在導入系統中實現它以遵循您的答案。所有未來的產品將具有的配置就像你說的,和目前的人都通過jQuery

catalogInventoryStockItemUpdateEntity stock; 

if (this.deliveryType != DeliveryTypes.Simple) 
{ 
    stock = new catalogInventoryStockItemUpdateEntity 
       { 
        use_config_manage_stockSpecified = true, 
        use_config_manage_stock = 0, 
        manage_stockSpecified = true, 
        manage_stock = 0, 
        backorders = 0, 
        is_in_stockSpecified = true, 
        is_in_stock = 1, 
        use_config_max_sale_qtySpecified = true, 
        use_config_max_sale_qty = 0, 
        max_sale_qtySpecified = true, 
        max_sale_qty = 1 
       }; 
} 
else 
{ 

    stock = new catalogInventoryStockItemUpdateEntity 
       { 
        manage_stockSpecified = true, 
        is_qty_decimal = 1, 
        is_qty_decimalSpecified = true, 
        qty = this.InventoryQuantity.ToString(CultureInfo.InvariantCulture), 
        backorders = 0, 
        is_in_stockSpecified = true, 
        is_in_stock = 1, 
        manage_stock = 1 
       }; 
} 

return stock; 

處理我繼承人如何使前端看起來更好一點。我添加了一個小的淡入淡出效果,並且數量發生了變化並解釋了它爲什麼會發生變化。我插入以下到我的主題 /var/www/app/design/frontend/NKI/default/template/catalog/product/view.phtml

<script type="text/javascript"> 

jQuery(document).ready(function() { 
    jQuery('#attribute501').change(function() { 
      var x = jQuery(this).val(); 
      // If its not a physical book 
      var qtyInput = jQuery('#theQty').find('#qty'); 
      jQuery(qtyInput).val(1); 
      var qtyExplain = jQuery('#qtyExplain'); 

      if (x) { 

        if (x != 3) { 
          jQuery(qtyExplain).fadeIn('slow'); 
          jQuery(qtyInput).attr("disabled",true); 
        } else { 
          jQuery(qtyExplain).fadeOut('slow'); 
          jQuery(qtyInput).attr("disabled",false); 
        } 
      } else { 
        jQuery(qtyExplain).fadeOut('slow'); 
        jQuery(qtyInput).attr("disabled",false); 

      } 
    }); 

}); 

</script> 

另外在 /無功/網絡/應用/設計/frontend/NKI/default/template/catalog/product/view/addtocart.phtml 我改成了這個

<?php $_product = $this->getProduct() ?> 

<?php if($_product->isSaleable()): ?> 
    <div class="add-to-cart" style="width: 365px"> 
     <?php if(!$_product->isGrouped()): ?> 
     <div id="qtyExplain" style="display:none"> 
       <p>Downloads are unlimited. Quantity is limited to one item.</p> 
     </div> 

     <div id="theQty" style="display: inline" > 
     <label for="qty"><?php echo $this->__('Qty:') ?></label> 
     <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" /> 
     </div> 
     <?php endif; ?> 
     <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="productAddToCartForm.submit()"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button> 
     <?php echo $this->getChildHtml('', true, true) ?> 
    </div> 
<?php endif; ?> 

此外,對於購物車,我下面的代碼添加到下列文件圍繞行154 /var/www/app/design/frontend/NKI/default/template/checkout/cart/item/default.phtml

<?php 
     if ($_item->getIsVirtual()): ?> 
       <span><?php echo $_item->getQty();?></span> 
     <?php else: ?> 

     <input name="cart[<?php echo $_item->getId() ?>][qty]" value="<?php echo $this->getQty() ?>" size="4" title="<?php echo $this->__('Qty') ?>" class="input-text qty" maxlength="12" /> 
     <?php endif; ?>