Pages

Tuesday, June 25, 2013

How to show product reviews on product page in Magento

Add the below code in the catalog.xml in the product view section

 <block type="review/product_view_list" name="product.info.product_additional_data" as="reviews" template="review/product/view/list.phtml"> 
 <block type="review/form" name="product.review.form" as="review_form"/></block>

And then include the below line in the view.phtml file

<? getChildHtml('reviews') ?>

unable to complete this request attribute set magento

simply delete the files and folder from the var/cache folder and var/sessions folder and then try.It will work.

Magento pages in a drop down (html select box).

below is the code to show magento pages in a drop down box

<select name=”page”>
<?php foreach (Mage::getResourceModel(‘cms/page_collection’) as $page){ ?>
<option value=”<?php echo $page->getId() ?>”><?php echo $page->getTitle() ?></option>
<?php } ?>
</select>

Get cms static block in magento

Here is the code to get the cms block in magento front end.
$this->getLayout()->createBlock(‘cms/block’)->setBlockId(‘blockidentifier’)->toHtml()
In the editor you can simply call to
{{block id=’block_id’}}
Similar reference
{{store direct_url=’mypage.html’}}
{{skin url=’images/media/about_us_img.jpg’}}

Add Category Filter on Product Collection In Magento

Here is the code to add category filter on the product collection
$productcollection = Mage::getModel(‘catalog/product’)->getCollection();
$productcollection = $productcollection->addCategoryFilter(Mage::getModel(‘catalog/category’)->load($currcategory),true);
$productcollection = $productcollection->addAttributeToFilter(‘special_price’, array(‘gt’ => 0));
echo $productcollection->getSize();

Current page variable in magento

Get title
<?=Mage::getSingleton(‘cms/page’)->getTitle()?>

Get Identifier
<? echo Mage::getBlockSingleton(‘cms/page’)->getPage()->getIdentifier()?>

Get Page ID
<? echo Mage::getBlockSingleton(‘cms/page’)->getPage()->getId()?>

Fetch configurable product attributes values

Getting all options of a specific magento configurable product attribute is fairly easy:



getAttribute('catalog_product', 'color');
foreach ($attribute->getSource()->getAllOptions(true) as $option) {
echo $option['value'] . ' ' . $option['label'] . "\n";
}
?>




get options and their values which are applicable to a particular configurable product



getTypeInstance(true)->getConfigurableAttributesAsArray($product);
$attributeOptions = array();
foreach ($productAttributeOptions as $productAttribute) {
foreach ($productAttribute['values'] as $attribute) {
$attributeOptions[$productAttribute['label']][$attribute['value_index']] = $attribute['store_label'];
}
}
?>

Magento : Product count in a category.

Below are the 2 different way to display the product count in the category in magento.
<?php
$catObj = Mage::getModel(‘catalog/category’)->load($_category->getID());
$prodObj = $catObj->getProductCollection()->getData();
echo count($prodObj);
———————-OR————————–
$prodCollection = Mage::getResourceModel(‘catalog/product_collection’)->addCategoryFilter($_category);
echo $prodCollection->count();
?>

Delete Orders From Magento and Reset The Order Id

1. Take the backup of your current database
2. Run the below queries
3. I have not fully tested that what will be the effect of these queries on the database, but as much i tested it does not have any negative effect on the Magento Database
4. If you find any wrong effect then your comment are welcome
These are the queries to delete the orders on the magento and reset the Id
—————————————————————-
SET FOREIGN_KEY_CHECKS=0;

TRUNCATE `sales_flat_order`;
TRUNCATE `sales_flat_order_address`;
TRUNCATE `sales_flat_order_grid`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sales_flat_order_payment`;
TRUNCATE `sales_flat_order_status_history`;

TRUNCATE `sales_flat_creditmemo`;
TRUNCATE `sales_flat_creditmemo_comment`;
TRUNCATE `sales_flat_creditmemo_grid`;
TRUNCATE `sales_flat_creditmemo_item`;

TRUNCATE `sales_flat_invoice`;
TRUNCATE `sales_flat_invoice`;
TRUNCATE `sales_flat_invoice_grid`;
TRUNCATE `sales_flat_invoice_item`;

TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_order_item`;

TRUNCATE `sales_flat_shipment`;
TRUNCATE `sales_flat_shipment_comment`;
TRUNCATE `sales_flat_shipment_grid`;
TRUNCATE `sales_flat_shipment_item`;
TRUNCATE `sales_flat_shipment_item`;
TRUNCATE `sales_flat_shipment_track`;

TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;

ALTER TABLE `sales_flat_order` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_order_address` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_order_grid` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_order_payment` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_order_status_history` AUTO_INCREMENT=0;

ALTER TABLE `sales_flat_creditmemo` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_creditmemo_comment` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_creditmemo_grid` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_creditmemo_item` AUTO_INCREMENT=0;

ALTER TABLE `sales_flat_invoice` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_invoice` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_invoice_grid` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_invoice_item` AUTO_INCREMENT=0;

ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=0;

ALTER TABLE `sales_flat_shipment` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_shipment_comment` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_shipment_grid` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_shipment_item` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_shipment_item` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_shipment_track` AUTO_INCREMENT=0;

ALTER TABLE `sendfriend_log` AUTO_INCREMENT=0;
ALTER TABLE `tag` AUTO_INCREMENT=0;
ALTER TABLE `tag_relation` AUTO_INCREMENT=0;
ALTER TABLE `tag_summary` AUTO_INCREMENT=0;
ALTER TABLE `wishlist` AUTO_INCREMENT=0;
ALTER TABLE `log_quote` AUTO_INCREMENT=0;
ALTER TABLE `report_event` AUTO_INCREMENT=0;

TRUNCATE `eav_entity_store`;
ALTER TABLE `eav_entity_store` AUTO_INCREMENT=0;

SET FOREIGN_KEY_CHECKS=1;

----------------------------------------------------------

Fetch Subcategory of a category in magento in select box dropdown

<select name="" style="width:220px;" onchange="location.href=this.value">
  <?php $children  = Mage::getModel('catalog/category')->getCategories(YOUR_CAT_ID); ?>

 <?php foreach ($children as $category) {  $i++;
 $cat = Mage::getModel('catalog/category')->load($category->getID()); ?>
  <option value="<?php echo $cat->geturl(); ?>"  <? if(Mage::registry('current_category')->getId()==$category->getID()) echo 'selected';?>><?php echo $category->getName(); ?></option>
 <?php } ?>

 </select>