Thursday 26 December 2013

Get products from particular category Magento

 <?php $categoryIds = array(3,4);//category id

                                    $collection = Mage::getModel('catalog/product')
                                    ->getCollection()
                                    ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
                                    ->addAttributeToSelect('*')
                                    ->addAttributeToFilter('category_id', array('in' => $categoryIds))
                    ?>
                   
                    <?php $_collectionSize = $collection->count() ?>
    <?php //$_columnCount = $this->getColumnCount(); ?>
    <?php $i=0; foreach ($collection as $product): ?>
        <?php if ($i++%4==0): ?>
        <ul class="products-grid">
        <?php endif ?>
            <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                <a href="<?php echo $product->getProductUrl()?>" title="<?php echo $product->getName()?>">
                        <img src="<?php echo Mage::helper('catalog/image')->init($product, 'small_image')->resize(197, 167); ?>" alt="<?php echo $product->getName()?>" border="0" />
                    </a>
                <h2 class="product-name"><a href="<?php echo $product->getProductUrl()?>" title="<?php echo $product->getName()?>"><?php echo $product->getName() ?></a></h2>
               <div class="price-box">
               <?php echo Mage::helper('core')->currency($product->getPrice(),true,false);?>
               </div>
                <div class="actions">
                    <?php if($product->isSaleable()): ?>
                        <button class="button" onclick="setLocation('<?php echo Mage::getUrl('checkout/cart/add/')?>product/<?php echo $product->getId() ?>/')" title="<?php echo $this->__('Köp');?>" type="submit"><span><span><?php echo $this->__('Köp');?></span></span></button>
                    <?php else: ?>
                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>

                </div>
            </li>
        <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
        </ul>
        <?php endif ?>
        <?php endforeach ?>

Friday 13 December 2013

get custom options programatically Magento

Hi with the below code you can get the product custom  option attributes all data


$product = Mage::getModel("catalog/product")->load(1); //product id 1
$i = 1;
echo "<pre>";
foreach ($product->getOptions() as $o) {
    echo "<strong>Custom Option:" . $i . "</strong><br/>";
    echo "Custom Option TITLE: " . $o->getTitle() . "<br/>"; //Colors
    echo "Custom Option TYPE: " . $o->getType() . "<br/>"; //drop_down
    echo "Custom Option Values: <br/>";
    $values = $o->getValues();
    foreach ($values as $v) {
        print_r($v->getData());
    }
    $i++;
    echo "<br/>";
}