Category Name with Products in Cart Page Magento
Modify Your Cart.phtml
<div class="cart">
<div class="page-title title-buttons">
<h1><?php
echo $this->__('Shopping Cart') ?></h1>
<?php if(!$this->hasError()): ?>
<ul class="checkout-types">
<?php foreach ($this->getMethods('top_methods') as $method): ?>
<?php if ($methodHtml = $this->getMethodHtml($method)): ?>
<li><?php echo $methodHtml; ?></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<?php echo $this->getChildHtml('form_before') ?>
<form action="<?php echo $this->getUrl('checkout/cart/updatePost') ?>" method="post">
<fieldset>
<table id="shopping-cart-table" class="data-table cart-table">
<col width="1" />
<col />
<col width="1" />
<?php if ($this->helper('wishlist')->isAllowInCart()) : ?>
<col width="1" />
<?php endif ?>
<?php if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
<col width="1" />
<?php endif; ?>
<?php if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
<col width="1" />
<?php endif; ?>
<col width="1" />
<?php if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
<col width="1" />
<?php endif; ?>
<?php if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
<col width="1" />
<?php endif; ?>
<col width="1" />
<?php $mergedCells = ($this->helper('tax')->displayCartBothPrices() ? 2 : 1); ?>
<thead>
<tr>
<th rowspan="<?php echo $mergedCells; ?>"> </th>
<th rowspan="<?php echo $mergedCells; ?>"><span class="nobr"><?php echo $this->__('Product Name') ?></span></th>
<th rowspan="<?php echo $mergedCells; ?>"></th>
<?php if ($this->helper('wishlist')->isAllowInCart()) : ?>
<th rowspan="<?php echo $mergedCells; ?>" class="a-center"><span class="nobr"><?php echo $this->__('Move to Wishlist') ?></span></th>
<?php endif ?>
<th class="a-center" colspan="<?php echo $mergedCells; ?>"><span class="nobr"><?php echo $this->__('Unit Price') ?></span></th>
<th rowspan="<?php echo $mergedCells; ?>" class="a-center"><?php echo $this->__('Qty') ?></th>
<th class="a-center" colspan="<?php echo $mergedCells; ?>"><?php echo $this->__('Subtotal') ?></th>
<th rowspan="<?php echo $mergedCells; ?>" class="a-center"> </th>
</tr>
<?php if ($this->helper('tax')->displayCartBothPrices()): ?>
<tr>
<th class="a-right"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
<th><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
<th class="a-right"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
<th><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
</tr>
<?php endif; ?>
</thead>
<tfoot>
<tr>
<td colspan="50" class="a-right">
<?php if($this->getContinueShoppingUrl()): ?>
<button type="button" title="<?php echo $this->__('Continue Shopping') ?>" class="button btn-continue" onclick="setLocation('<?php echo $this->getContinueShoppingUrl() ?>')"><span><span><?php echo $this->__('Continue Shopping') ?></span></span></button>
<?php endif; ?>
<button type="submit" title="<?php echo $this->__('Update Shopping Cart') ?>" class="button btn-update"><span><span><?php echo $this->__('Update Shopping Cart') ?></span></span></button>
</td>
</tr>
</tfoot>
<tbody><?php $price=0;
?>
<?php foreach($this->getItems() as $_item):
echo $_item->getName()."---". $_item->getProductId();
$all_category_ids = $_item->getProduct()->getCategoryIds();
foreach ( $all_category_ids as $cart_category_id )
{
$category_model = Mage::getModel('catalog/category')->load($cart_category_id);
$cat_Id = $category_model->getId();
break;
}
$newcat[]=$cat_Id;
$nprice[]=array("cat_id"=>$cat_Id,"price"=>$_item->getRowTotal());
/*$newarr[]=array($cat_Id=>$_item->getRowTotal();
if (array_key_exists($cat_Id, $newarr))
*/
echo $this->getItemHtml($_item) ?>
<?php endforeach ?>
<?php //echo $price."<pre>";/* print_r($newarr); */
/* print_r(array_count_values($newcat));
print_r($newcat); */
// print_r($nprice);
$cat_price = '';
foreach($nprice as $index=>$value)
{
if ( array_key_exists($value['cat_id'], $cat_price) )
{
$cat_price[$value['cat_id']] = $cat_price[$value['cat_id']] + $value['price'];
}
else
{
$cat_price[$value['cat_id']] = $value['price'];
}
}
print_r($cat_price);
?> </tbody>
</table>
<script type="text/javascript">decorateTable('shopping-cart-table')</script>
</fieldset>
</form>
<div class="cart-collaterals">
<div class="col2-set">
<div class="col-1">
<?php if($_crosssell = $this->getChildHtml('crosssell')): ?>
<?php echo $_crosssell; ?>
<?php else: ?>
<div class="no-crosssell">
<img src="<?php echo $this->getSkinUrl('images/media/callout1.jpg') ?>" alt="" />
<img src="<?php echo $this->getSkinUrl('images/media/fpo_no_crosssell.gif') ?>" alt="" />
</div>
<?php endif; ?>
</div>
<div class="col-2">
<?php echo $this->getChildHtml('coupon') ?>
<?php if (!$this->getIsVirtual()): echo $this->getChildHtml('shipping'); endif; ?>
<div class="totals">
<?php echo $this->getChildHtml('totals'); ?>
<?php if(!$this->hasError()): ?>
<?php foreach($cat_price as $cat_val){
if($cat_val <5){?>
<ul class="checkout-types">
<li>One of the restorents price is less than 5 euro.</li>
</ul>
<?php $flag=1;
break;
}
}?>
<?php if($flag !=1){?>
<ul class="checkout-types">
<?php foreach ($this->getMethods('methods') as $method): ?>
<?php if ($methodHtml = $this->getMethodHtml($method)): ?>
<li><?php echo $methodHtml; ?></li>
<?php endif; ?>
<?php endforeach; ?>
</ul><?php }
?>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<div class="cart">
<div class="page-title title-buttons">
<h1><?php
echo $this->__('Shopping Cart') ?></h1>
<?php if(!$this->hasError()): ?>
<ul class="checkout-types">
<?php foreach ($this->getMethods('top_methods') as $method): ?>
<?php if ($methodHtml = $this->getMethodHtml($method)): ?>
<li><?php echo $methodHtml; ?></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<?php echo $this->getChildHtml('form_before') ?>
<form action="<?php echo $this->getUrl('checkout/cart/updatePost') ?>" method="post">
<fieldset>
<table id="shopping-cart-table" class="data-table cart-table">
<col width="1" />
<col />
<col width="1" />
<?php if ($this->helper('wishlist')->isAllowInCart()) : ?>
<col width="1" />
<?php endif ?>
<?php if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
<col width="1" />
<?php endif; ?>
<?php if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
<col width="1" />
<?php endif; ?>
<col width="1" />
<?php if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
<col width="1" />
<?php endif; ?>
<?php if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
<col width="1" />
<?php endif; ?>
<col width="1" />
<?php $mergedCells = ($this->helper('tax')->displayCartBothPrices() ? 2 : 1); ?>
<thead>
<tr>
<th rowspan="<?php echo $mergedCells; ?>"> </th>
<th rowspan="<?php echo $mergedCells; ?>"><span class="nobr"><?php echo $this->__('Product Name') ?></span></th>
<th rowspan="<?php echo $mergedCells; ?>"></th>
<?php if ($this->helper('wishlist')->isAllowInCart()) : ?>
<th rowspan="<?php echo $mergedCells; ?>" class="a-center"><span class="nobr"><?php echo $this->__('Move to Wishlist') ?></span></th>
<?php endif ?>
<th class="a-center" colspan="<?php echo $mergedCells; ?>"><span class="nobr"><?php echo $this->__('Unit Price') ?></span></th>
<th rowspan="<?php echo $mergedCells; ?>" class="a-center"><?php echo $this->__('Qty') ?></th>
<th class="a-center" colspan="<?php echo $mergedCells; ?>"><?php echo $this->__('Subtotal') ?></th>
<th rowspan="<?php echo $mergedCells; ?>" class="a-center"> </th>
</tr>
<?php if ($this->helper('tax')->displayCartBothPrices()): ?>
<tr>
<th class="a-right"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
<th><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
<th class="a-right"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
<th><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
</tr>
<?php endif; ?>
</thead>
<tfoot>
<tr>
<td colspan="50" class="a-right">
<?php if($this->getContinueShoppingUrl()): ?>
<button type="button" title="<?php echo $this->__('Continue Shopping') ?>" class="button btn-continue" onclick="setLocation('<?php echo $this->getContinueShoppingUrl() ?>')"><span><span><?php echo $this->__('Continue Shopping') ?></span></span></button>
<?php endif; ?>
<button type="submit" title="<?php echo $this->__('Update Shopping Cart') ?>" class="button btn-update"><span><span><?php echo $this->__('Update Shopping Cart') ?></span></span></button>
</td>
</tr>
</tfoot>
<tbody><?php $price=0;
?>
<?php foreach($this->getItems() as $_item):
echo $_item->getName()."---". $_item->getProductId();
$all_category_ids = $_item->getProduct()->getCategoryIds();
foreach ( $all_category_ids as $cart_category_id )
{
$category_model = Mage::getModel('catalog/category')->load($cart_category_id);
$cat_Id = $category_model->getId();
break;
}
$newcat[]=$cat_Id;
$nprice[]=array("cat_id"=>$cat_Id,"price"=>$_item->getRowTotal());
/*$newarr[]=array($cat_Id=>$_item->getRowTotal();
if (array_key_exists($cat_Id, $newarr))
*/
echo $this->getItemHtml($_item) ?>
<?php endforeach ?>
<?php //echo $price."<pre>";/* print_r($newarr); */
/* print_r(array_count_values($newcat));
print_r($newcat); */
// print_r($nprice);
$cat_price = '';
foreach($nprice as $index=>$value)
{
if ( array_key_exists($value['cat_id'], $cat_price) )
{
$cat_price[$value['cat_id']] = $cat_price[$value['cat_id']] + $value['price'];
}
else
{
$cat_price[$value['cat_id']] = $value['price'];
}
}
print_r($cat_price);
?> </tbody>
</table>
<script type="text/javascript">decorateTable('shopping-cart-table')</script>
</fieldset>
</form>
<div class="cart-collaterals">
<div class="col2-set">
<div class="col-1">
<?php if($_crosssell = $this->getChildHtml('crosssell')): ?>
<?php echo $_crosssell; ?>
<?php else: ?>
<div class="no-crosssell">
<img src="<?php echo $this->getSkinUrl('images/media/callout1.jpg') ?>" alt="" />
<img src="<?php echo $this->getSkinUrl('images/media/fpo_no_crosssell.gif') ?>" alt="" />
</div>
<?php endif; ?>
</div>
<div class="col-2">
<?php echo $this->getChildHtml('coupon') ?>
<?php if (!$this->getIsVirtual()): echo $this->getChildHtml('shipping'); endif; ?>
<div class="totals">
<?php echo $this->getChildHtml('totals'); ?>
<?php if(!$this->hasError()): ?>
<?php foreach($cat_price as $cat_val){
if($cat_val <5){?>
<ul class="checkout-types">
<li>One of the restorents price is less than 5 euro.</li>
</ul>
<?php $flag=1;
break;
}
}?>
<?php if($flag !=1){?>
<ul class="checkout-types">
<?php foreach ($this->getMethods('methods') as $method): ?>
<?php if ($methodHtml = $this->getMethodHtml($method)): ?>
<li><?php echo $methodHtml; ?></li>
<?php endif; ?>
<?php endforeach; ?>
</ul><?php }
?>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
Comments
Post a Comment