Category : Magento

Magento – Categories Images

Get category image: <?php $_category = $this->getCurrentCategory(); $_imageUrl = $this->getImageUrl(); ?> Get category thumbnail: <?php $_category = $this->getCurrentCategory(); $_imageUrl = $this->getThumbnail(); ?>

Magento get child products for a configurable product

Magento get products childs for a configurable product // $currentProduct = $this->getProduct(); $configurable_products = Mage::getModel(‘catalog/product_type_configurable’)->setProduct($currentProduct); $products_collection = $configurable_products->getUsedProductCollection()->addAttributeToSelect(‘*’)->addFilterByRequiredOptions(); foreach($products_collection as $_product){ echo $_product->getId() . “: ” . $_product->getName(); }

Magento – Show Quantity Box in Products List

In file ‘list.phtml’ file change the <button> line near line 108 from this: <?php if($_product->isSaleable()): ?> <button class=”form-button” onclick=”setLocation(‘<?php echo $this->getAddToCartUrl($_product) ?<‘)”>>span> <?php echo $this->__(‘Add to Cart’) ?></span></button> with: <form action=” <?php echo $this->getAddToCartUrl($_product) ?>” method=”post” id=”product_addtocart_form_<?php echo $_product->getId(); ?>”> <input name=”qty” type=”text” class=”input-text qty” id=”qty” maxlength=”12″ value=” <?php echo $this->getMinimalQty($_product) ?>” /> <button class=form-button”

Read More →

Magento – use singleton database connection

Magento database connection write mode: $db = Mage::getSingleton(‘core/resource’)->getConnection(‘core_write’); Magento database connection read mode: $db = Mage::getSingleton(‘core/resource’)->getConnection(‘core_read’); Query model $result = $db->query(“SELECT * FROM tablename”); if ($result) { while ($row = $result->fetch(PDO::FETCH_ASSOC)) { // Use $row } }

Magento – custom block

Custom block (for CMS pages): {{block type=”core/template” name=”template_name” template=”mydir/mytemplate.phtml” }}

Magento – save and get data from cache

Just a method to save and get data from magento cache $mydataforcache = “My data for cache”; $cache_name = “maycachename”; $CACHEDATA = MAGE::app()->loadCache($cache_name); if (isset($CACHEDATA) && ($CACHEDATA != “”)) { // Use data echo $CACHEDATA; } else { // Save data to cache Mage::app()->saveCache($mydataforcache, $cache_name, array(), 10800); }

Magento get customer group Id and group name

Get customer group Id // Check if costomer is logged in if(Mage::getSingleton(‘customer/session’)->isLoggedIn()) { // Get group Id $groupId = Mage::getSingleton(‘customer/session’)->getCustomerGroupId(); } Get group name: $group = Mage::getModel(‘customer/customer_group’)->load($groupId); $group->getName();

1 2 3