我需要预设产品页面上的产品数量。

nb1:我的产品有新的是/否在后端定义的属性,称为formure_price - 活动。 NB2:对于Forumal_price_active产品,我通过产品URL通过参数来预先配置我的产品页面

我将view.php类扩展到添加/过载自定义函数:

    <?php
    class Mine_Quotemodule_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_View
    {
        /**
         * Get default qty - either as preconfigured, or as 1.
         * Also restricts it by minimal qty.
         *
         * @param null|Mage_Catalog_Model_Product $product
         * @return int|float
         */
        public function getProductDefaultQty($product = null)
        {
            if (!$product) {
                $product = $this->getProduct();
            }

            $FPA_att_value = $product->getAttributeText('formula_price_active');

            if (isset($FPA_att_value) && (($FPA_att_value == 'yes') || ($FPA_att_value == 'oui')))
            {
                $params = Mage::app()->getRequest()->getParams();
                $urlParams = array();

                foreach ($params as $name=>$value)
                {
                    if ($name!="id") 
                    {
                    $urlParams[$name] = base64_decode($value);
                    }
                }

                if (isset($urlParams['Devis_Qty']))
                {
                    $qty = $urlParams['Devis_Qty'];
                }   
                else 
                {               
                    $qty = $this->getMinimalQty($product);
                    $config = $product->getPreconfiguredValues();
                    $configQty = $config->getQty();
                    if ($configQty > $qty) {
                        $qty = $configQty;
                    }
                }
            }
            else
            {
                $qty = $this->getMinimalQty($product);
                Mage::log('Qty'.$qty);

                $config = $product->getPreconfiguredValues();
                $configQty = $config->getQty();
                Mage::log('configQty '.$configQty);
                if ($configQty > $qty) {
                    $qty = $configQty;
                }

            }
            Mage::log('Final Qty'.$qty);
            return $qty;

        }

        public function testProductFP($product = null)
        {
             if (!$product) {
                $product = $this->getProduct();
            }

            $FPA_att_value = $product->getAttributeText('formula_price_active');

            if (isset($FPA_att_value) && (($FPA_att_value == 'yes') || ($FPA_att_value == 'oui')))
            {
                $params = Mage::app()->getRequest()->getParams();
                $urlParams = array();

                foreach ($params as $name=>$value)
                {
                    if ($name!="id") 
                    {
                    $urlParams[$name] = base64_decode($value);
                    }
                }

                if (isset($urlParams['Devis_Qty']))
                {
                    $result = true;
                }   
                else 
                {               
                    $result = false;
                }
            }
            else
            {
                $result = false;
            }

            return $result;
        }
...
.

和view.phtml添加自定义东西(但是理论上与当前问题无关):

…

                <div class="extra-info">
                    <?php echo $this->getReviewsSummaryHtml($_product, 'default', false)?>

                    <!-- Modifs Perso -->
                    <!--<?php echo $this->getChildHtml('product_type_availability'); ?>-->
                    <?php echo $this->getDimHtml() ?>
                    <!-- ******************** -->

                </div>
…
.

这似乎很好: - 案例1:如果公式_price_active设置为否或设置为yes但不存在所需的参数,则使用基本getDefaultQuantity方法 -case 2:当公式_price_active设置为yes和parameter是可以的,它设置了想要的数量。

然后我添加了一个自定义addtocart.phtml,以便在案例2中禁用数量输入。

但是,当我将它添加到我的layout.xml时,出现的问题:

在案例2中它是工作的,但在一个情况下,数量设置为0?

是什么奇怪的是,数量的布局如定义...

这是我的layout.xml

  <?xml version="1.0"?>
    <layout version="0.1.0">
        <default>
            <reference name="content">
            </reference>
            <reference name="head">
                <action method="addItem"><type>skin_css</type><name>css/quote_form.css</name></action>
            </reference>
        </default>

        <routeurfrontend_index_index>
            <reference name="content">
                <block type="quotemodule/quoteformblock"  name="quoteform_quoteformblock"
                              template="quotemodule/quoteform.phtml" />
            </reference>
        </routeurfrontend_index_index>

        <catalog_product_view>
            <reference name="product.info">
                <action method="setTemplate">
                    <template>quotemodule/catalog/product/view.phtml</template>
                </action>
            </reference>

            <reference name="product.info.addtocart">
                <action method="setTemplate">
                    <template>quotemodule/catalog/product/view/addtocart.phtml</template>
                </action>
            </reference>
        </catalog_product_view>

    </layout>
.

谢谢你的帮助,

有帮助吗?

解决方案

这是一个愚蠢的错误......对不起...

I基于错误的模板上的我的addtocart.phtml(基本/默认而不是RWD /默认值)。如果getProductDefaultQty返回null,则基本/默认值不会将数值值替换为1,而RWD /默认值为:

base / default addtocart.phtml

<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
.

rwd / default addtocart.phtml

<input type="text" pattern="\d*" name="qty" id="qty" maxlength="12" value="<?php echo max($this->getProductDefaultQty() * 1, 1) ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
.

许可以下: CC-BY-SA归因
scroll top