View Single Post
  #4  
Old 08-20-2014, 01:56 PM
 
jp@ewaycorp.com jp@ewaycorp.com is offline
 

Member
  
Join Date: Aug 2009
Posts: 23
 

Thumbs up Re: Show product variant in list view instead of drop down

I have figured out how to do it on my own.
PHP Code:
protected function getVariantsInfo() 
    {

        
$product $this->getProduct();
        
//echo $id = $product->getProductId();
        
        
$variants $product->getVariants(); 

        foreach (
$variants as $variant) {
            
$v_info=array();
            
$v_info['quantity']=(($variant->defaultAmount) ? $product->getQty() : $variant->amount);
            
$v_info['price']=(($variant->defaultPrice) ? $product->price $variant->price);
            
$v_info['sku']=(($variant->sku) ? $product->sku $variant->sku);
            
$v_info['product_id'] = $product->getProductId();
            
$v_info['category_id'] = $product->getCategoryId();
            
$v_info['attr_group_id'] = "62"// Your select box ID
            
foreach($variant->getAttributeValues() as $attribute)
            {
                
$v_info['media_type']= trim($attribute->getAttributeOption()->getName());
                
$v_info['attribute_id'] = $attribute->getId();
            }
            
$variant_info[]=$v_info;
        }
        return 
$variant_info
    } 

In Template File

Code:
{foreach:getVariantsInfo(),a} <li> <span class="icon"><img src="images/cd-icon.png" alt="cd-icon"></span> <span class="details-with-sku">{product.name:h} ({a.media_type})<br/><p>SKU: {a.sku}</p></span> <span class="buy-now"> ${a.price}<br/> <form action="{buildURL(#cart#)}" method="post" accept-charset="utf-8"> <div class="form-params" style="display: none;"> <input type="hidden" name="target" value="cart"> <input type="hidden" name="action" value="add"> <input type="hidden" name="product_id" value="{a.product_id}"> <input type="hidden" name="category_id" value="{a.category_id}"> <input type="hidden" name="attribute_values[{a.attr_group_id}]" value="{a.attribute_id}"> <input type="hidden" name="amount" value="1"> <input type="hidden" name="returnURL" value="{product.cleanURL}"> </div> <input class="add_to_cart_mediatype" type="submit" value="" /> </form> </span> <div class="clearfix"></div> </li> {end:}

Now you can have a list of variant with buy now button and clicking on it will add the specific variant to your cart.

I hope this would help someone who is trying to figure out this kind of requirement.

Also print_r is done like this

Code:
echo "<pre>"; \Doctrine\Common\Util\Debug::dump($entity); echo "</pre>";
Reply With Quote