什么是限制magento中可下载产品购买数量的好方法

什么是限制magento中可下载产品购买数量的好方法,magento,download,limit,product,Magento,Download,Limit,Product,首先:我了解magento的mvc和php,但我并不完全了解它的“内置功能”可以做什么 我正在研究一种方法,当用户选择我的一本书的可配置产品作为epub或pdf版本时,将数量限制为1。我准备开始在主题中使用jQuery巫毒来解决这个问题,如果选择不是物理的,则隐藏数量选项。我希望有人知道这样做的方法,或者有这样做的经验 请随意回答,在管理员中执行此操作或编写类似的代码 谢谢您可以通过编辑购物车并转到“库存”选项卡来限制特定商品在购物车中允许的商品数量。有两种设置:购物车允许的最小数量和购物车允许

首先:我了解magento的mvc和php,但我并不完全了解它的“内置功能”可以做什么

我正在研究一种方法,当用户选择我的一本书的可配置产品作为epub或pdf版本时,将数量限制为1。我准备开始在主题中使用jQuery巫毒来解决这个问题,如果选择不是物理的,则隐藏数量选项。我希望有人知道这样做的方法,或者有这样做的经验

请随意回答,在管理员中执行此操作或编写类似的代码


谢谢

您可以通过编辑购物车并转到“库存”选项卡来限制特定商品在购物车中允许的商品数量。有两种设置:购物车允许的最小数量和购物车允许的最大数量。取消选中允许的最大数量的使用配置设置,并将其设置为一


默认情况下,这两个都是使用配置,这意味着它也可以在系统->配置->库存选项卡中进行编辑。

您可以通过编辑特定项目并转到库存选项卡来限制购物车中允许的项目数。有两种设置:购物车允许的最小数量和购物车允许的最大数量。取消选中允许的最大数量的使用配置设置,并将其设置为一


默认情况下,这两个都是使用配置,这意味着它也可以在系统->配置->库存选项卡中进行编辑。

以下是我如何在导入系统中实现它以遵循您的答案。所有未来的产品都将具有如您所说的配置,当前的产品将通过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>
也在 /var/www/app/design/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; ?>

下面是我如何在导入系统中实现它以遵循您的答案。所有未来的产品都将具有如您所说的配置,当前的产品将通过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>
也在 /var/www/app/design/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; ?>

回答得好。我应该早点回来看看。我编写了jquery。我可以改用这种方法。我的所有产品都是通过soap调用导入的。magento2的回答是:后端>商店>配置>目录>投资>产品股票期权>购物车中允许的最大数量:=1正确答案。我应该早点回来看看。我编写了jquery。我可以改用这种方法。我的所有产品都是通过soap调用导入的。magento2的回答是:后端>商店>配置>目录>投资>产品股票期权>购物车中允许的最大数量:=1