Pages

Wednesday, 31 December 2014

Magento:: checkout as guest enable/disable

By default, in Magento guests can shop without creating a customer account on your site. If you want to, you can disable guest checkout and allow only registered users to purchase products from your store. You can do this from the admin panel of your Magento.

After you log in go to System menu>Configuration>Checkout button in the Sales section on the left>Checkout Options panel on the right. After you expand the Checkout Options panel you'll see a drop-down menu Allow Guest Checkout; just set it to No. Once you do that a drop-down menu will appear under it labeled Require Customer To Be Logged in To Checkout; set it to Yes and click on the Save Config button in the upper right corner.

Tuesday, 30 December 2014

Magento:: How to remove all catalog products

Reset all product tables. Beware, below script will delete ALL your product data so do it carefully.


To remove all product go to the database and run the following query
SET FOREIGN_KEY_CHECKS = 0;

TRUNCATE TABLE `catalog_product_bundle_option`;
TRUNCATE TABLE `catalog_product_bundle_option_value`;
TRUNCATE TABLE `catalog_product_bundle_selection`;
TRUNCATE TABLE `catalog_product_entity_datetime`;
TRUNCATE TABLE `catalog_product_entity_decimal`;
TRUNCATE TABLE `catalog_product_entity_gallery`;
TRUNCATE TABLE `catalog_product_entity_int`;
TRUNCATE TABLE `catalog_product_entity_media_gallery`;
TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
TRUNCATE TABLE `catalog_product_entity_text`;
TRUNCATE TABLE `catalog_product_entity_tier_price`;
TRUNCATE TABLE `catalog_product_entity_varchar`;
TRUNCATE TABLE `catalog_product_link`;
TRUNCATE TABLE `catalog_product_link_attribute`;
TRUNCATE TABLE `catalog_product_link_attribute_decimal`;
TRUNCATE TABLE `catalog_product_link_attribute_int`;
TRUNCATE TABLE `catalog_product_link_attribute_varchar`;
TRUNCATE TABLE `catalog_product_link_type`;
TRUNCATE TABLE `catalog_product_option`;
TRUNCATE TABLE `catalog_product_option_price`;
TRUNCATE TABLE `catalog_product_option_title`;
TRUNCATE TABLE `catalog_product_option_type_price`;
TRUNCATE TABLE `catalog_product_option_type_title`;
TRUNCATE TABLE `catalog_product_option_type_value`;
TRUNCATE TABLE `catalog_product_super_attribute`;
TRUNCATE TABLE `catalog_product_super_attribute_label`;
TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
TRUNCATE TABLE `catalog_product_super_link`;
TRUNCATE TABLE `catalog_product_enabled_index`;
TRUNCATE TABLE `catalog_product_website`;
TRUNCATE TABLE `catalog_product_entity`;

TRUNCATE TABLE `cataloginventory_stock`;
TRUNCATE TABLE `cataloginventory_stock_item`;
TRUNCATE TABLE `cataloginventory_stock_status`;
SET FOREIGN_KEY_CHECKS = 1;
INSERT  INTO `catalog_product_link_type`(`link_type_id`,`code`) VALUES (1,'relation'),(2,'bundle'),(3,'super'),(4,'up_sell'),(5,'cross_sell');
INSERT  INTO `catalog_product_link_attribute`(`product_link_attribute_id`,`link_type_id`,`product_link_attribute_code`,`data_type`) VALUES (1,2,'qty','decimal'),(2,1,'position','int'),(3,4,'position','int'),(4,5,'position','int'),(6,1,'qty','decimal'),(7,3,'position','int'),(8,3,'qty','decimal');
INSERT  INTO `cataloginventory_stock`(`stock_id`,`stock_name`) VALUES (1,'Default');
Note: Then you may require re-indexing all your indexes after running above query.
for that go to System > Index Management > Reindex all.

Magento:: Difference between Mage::getSingleton() and Mage::getModel()

Mage::getSingleton()


Mage::getSingleton() will first check the same class instance is exits or not in memory. If the instance is created then it will return the same object from memory. So Mage::getSingleton() faster then Mage::getModel().
$product1 = Mage::getSingleton('catalog/product');
$product2 = Mage::getSingleton('catalog/product');
$product1 and $product2 both will share same memory of OS and return only one instance each time.

Mage::getgetModel()


Mage::getModel() will create a new instance of an object each time even such object exists in configuration.
$product1 = Mage::getModel('catalog/product');
$product2 = Mage::getModel('catalog/product');
$product1 and $product2 both have different instant of same object and also occupy different memory .

Wednesday, 24 December 2014

Magento:: Get Current Url

<?php

     $GetUrl=Mage::helper('core/url')->getCurrentUrl();
     echo "Current Url".$GetUrl;
?>

Tuesday, 23 December 2014

Magento:: Get all Cms Pages Link

<?php $collection = Mage::getModel('cms/page')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId());?>

<?php  $collection->getSelect()
->where('is_active = 1'); ?>
<ul id="nav">
<?php foreach ($collection as $page): ?>
<?php $PageData = $page->getData(); ?>
<?php// print_r($PageData);?>
<?php if($PageData['identifier']!='no-route' && $PageData['identifier']!='enable-cookies' && $PageData['identifier']!='home2') { ?>
<li>
<a href="<?php echo $this->getUrl('').$PageData['identifier']?>"><span><?php echo $PageData['title'] ?></span></a>
</li>
<?php } ?>
<?php endforeach; ?>
</ul>