Saturday, 27 August 2016

Magento : Get Current Store Details (ID, Code, Name and Status)

// Gets the current store's details
$store = Mage::app()->getStore();

// Gets the current store's id
$storeId = Mage::app()->getStore()->getStoreId();

// Gets the current store's code
$storeCode = Mage::app()->getStore()->getCode();

// Gets the current website's id
$websiteId = Mage::app()->getStore()->getWebsiteId();

// Gets the current store's group id
$storeGroupId = Mage::app()->getStore()->getGroupId();

// Gets the current store's name
$storeName = Mage::app()->getStore()->getName();

// Gets the current store's sort order
$storeSortOrder = Mage::app()->getStore()->getSortOrder();

// Gets the current store's status
$storeIsActive = Mage::app()->getStore()->getIsActive();

// Gets the current store's locale
$storeLocaleCode = Mage::app()->getStore()->getLocaleCode();

// Gets the current store's home url
$storeHomeUrl = Mage::app()->getStore()->getHomeUrl();

MAGENTO : EXPORT CATEGORIES AND IDS TO CSV




<?php
require_once 'app/Mage.php';
Mage::app();
$allCategories = Mage::getModel ( 'catalog/category' );
$categoryTree = $allCategories->getTreeModel();
$categoryTree->load();
$categoryIds = $categoryTree->getCollection()->getAllIds();
if ($categoryIds) {
$outputFile = "var/export/categories-and-ids.csv";
$write = fopen($outputFile, 'w');
foreach ( $categoryIds as $categoryId ) {
$data = array($allCategories->load($categoryId)->getName(), $categoryId);
fputcsv($write, $data);
}
}
fclose($write);
?>

Tuesday, 23 August 2016

Magento : Blank white screen frontend issue

Magento shows blank/empty page, I was scared when this happened on one of the live site but after some exercises with source code and using internet I come to find out the solution. Most probably it could have memory issue or the compilation tool.
In order to troubleshoot the issue,  your first step is to edit index.php, find out bellow line and uncomment
ini_set('display_errors', 1);
If its not available, insert this line somewhere at the top of the file and try out bellow solutions.
Try – 1 : Disable ComplierGo to System -> Tools -> Compilation and Disable you Complier and clear/flush magento cache data. In most of the cases this would solve the issue.
Try – 2 : Improve PHP Memory LimitIf you can access php.ini OR using .htaccess in the root OR edit index.php add bellow line right after ini_set(‘display_errors’, 1);
ini_set('memory_limit', '256M');
Try – 3 : Design changesIf you have recently installed new theme try to switch interface to a previously used one. Flush Magento cache after each operation. Magento will switch to default theme if it can not find a custom one.
I hope these would resolve  your problem.

Magento : Delete All Products Using PhpMyAdmin


Deleting all products on magento via the admin panel can be almost imposible when you have more than 10.000 products.

A quick way to do this would be thru phpmyadmin.

Before running this code please make sure you have a backup of the entire database.

This code worked fine on magento 1.7.0.2

Copy and paste this code @ phpmyadmin under SQL tab and run it.


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_label`;
TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
TRUNCATE TABLE `catalog_product_super_attribute`;
TRUNCATE TABLE `catalog_product_super_link`;
TRUNCATE TABLE `catalog_product_enabled_index`;
TRUNCATE TABLE `catalog_product_website`;
TRUNCATE TABLE `catalog_category_product_index`;
TRUNCATE TABLE `catalog_category_product`;
TRUNCATE TABLE `cataloginventory_stock_item`;
TRUNCATE TABLE `cataloginventory_stock_status`;
TRUNCATE TABLE `cataloginventory_stock`;
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');
TRUNCATE TABLE `catalog_product_entity`;
SET FOREIGN_KEY_CHECKS = 1;


Now you have Done! :)

Magento : Image upload error

Go to magneto root directory and find lib\Varien\File\Uploader.php

Edit file and go line no. 259


$params['object']->$params['method']($this->_file['tmp_name']);

should be

$params['object']->{$params['method']}($this->_file['tmp_name']);

Done! :)

Saturday, 20 August 2016

Magento : Unknown cipher in list: TLSv1 [duplicate]

First going to Curl.php in downloader/lib/Mage/HTTP/Client/Curl.php,

Edit file going to line no 377 and try changing:

$this->curlOption(CURLOPT_SSL_CIPHER_LIST, 'TLSv1');

to

$this->curlOption(CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);

Done!

Magento : PHP extension "soap" must be loaded.

Going to php.ini file


I edited php.ini and removed the leading semicolon ( ; ) from extension=php_soap.dll.

like this

;extension=php_soap.dll
to
extension=php_soap.dll

After restarting Apache I was able to proceed with the installation without any other issues.

Done!