Thursday, 15 April 2010

php - Magento grid view qty box to show minimum qty -



php - Magento grid view qty box to show minimum qty -

i want qty box next add together cart button in grid category view products minimum quantity. have tried using code below , works except field shows '0'.

how can create field shows minimum quantity of product , not '0'.

this used modify list.phtml file:

<?php if(!$_product->isgrouped()): ?> <label for="qty"><?php echo $this->__('qty:') ?></label> <input name="qty" type="text" class="input-text qty" id="qty" maxlength="12" value="<?php echo $this->getproductdefaultqty() * 1 ?>" title="<?php echo $this->__('qty') ?>" class="input-text qty" /> <?php endif; ?>

the function getproductdefaultqty available on view block , not list :(

you rewrite class mage_catalog_block_product_list client module , include function in module's class.

for sake of reply phone call module nat_quantity (you can alter if like)

step 1: create moudle xml

under /app/etc/modules/ create file nat_quantity.xml. should (note codepool has uppercase p).

<?xml version="1.0"?> <config> <modules> <nat_quantity> <active>true</active> <codepool>local</codepool> <depends> <mage_catalog /> </depends> </nat_quantity> </modules> </config>

step 2: create modules folder structure

under /app/code/local/ create folder nat, under there create folder quantity. under quantity folder create next 2 folders, etc , block. (note etc lowercase)

step 3: create config.xml

under /app/code/local/nat/quantity/etc create config.xml file like:

<?xml version="1.0"?> <config> <modules> <nat_quantity> <version>1.0.0</version> </nat_quantity> </modules> <global> <blocks> <catalog> <rewrite> <product_list>nat_quantity_block_product_list</product_list> </rewrite> </catalog> </blocks> </global> </config>

step 3: create block

under /app/code/local/nat/quantity/block/product create list.php looks follows:

<?php class nat_quantity_block_product_list extends mage_catalog_block_product_list { /** * default qty - either preconfigured, or 1. * restricts minimal qty. * * @param null|mage_catalog_model_product * * @return int|float */ public function getproductdefaultqty($product) { $qty = $this->getminimalqty($product); $config = $product->getpreconfiguredvalues(); $configqty = $config->getqty(); if ($configqty > $qty) { $qty = $configqty; } homecoming $qty; } }

this should allow in list template phone call $this->getproductdefaultqty($product). need pass function validate product or pass in product id , load product in function

$product = mage::getmodel('catalog/product')->load($productid);

php magento

No comments:

Post a Comment