HTML/JavaScript

Tuesday, August 2, 2016

Unknown date format, neither date nor time in ‘yyyy-MM-dd HH:mm:ss’ found

 Issues resolved
go to  file \lib\Zend\Locale\Format.php      line number 827

                 $day   = iconv_strpos($format, 'd');
        $month = iconv_strpos($format, 'M');
        $year  = iconv_strpos($format, 'y');
        $hour  = iconv_strpos($format, 'H');
        $min   = iconv_strpos($format, 'm');
        $sec   = iconv_strpos($format, 's');
Replace the code

        $day   = iconv_strpos($format, 'd',0,'UTF-8');
        $month = iconv_strpos($format, 'M',0,'UTF-8');
        $year  = iconv_strpos($format, 'y',0,'UTF-8');
        $hour  = iconv_strpos($format, 'H',0,'UTF-8');
        $min   = iconv_strpos($format, 'm',0,'UTF-8');
        $sec   = iconv_strpos($format, 's',0,'UTF-8');

and add the below code to add the following to your index.php:



iconv_set_encoding("internal_encoding","UTF-8");
iconv_set_encoding("output_encoding", "ISO-8859-1");

Thanks,

Tuesday, March 8, 2016

How do I get a website switcher instead of store switcher

You have to create a copy of the app/design/frontend/base/default/template/page/switch/stores.phtml template in your custom theme package.

Then you have to modify it to use the following code:


<?php
$websites = Mage::app()->getWebsites();

if (count($websites) > 1): ?>
<div class="website-switcher">
    <label for="select-website"><?php echo $this->__('Select Store:') ?></label>
    <select id="select-website" title="<?php echo $this->__('Select Store') ?>" onchange="location.href=this.value">
    <?php foreach ($websites as $website): // print out each website name and code as a dropdown box item ?>
        <?php $_selected = $website->getCode() == Mage::app()->getWebsite()->getCode() ? ' selected="selected"' : '' ?>
        <option value="<?php echo $website->getDefaultStore()->getBaseUrl()?>"<?php echo $_selected ?>><?php echo $this->htmlEscape($website->getName()) ?></option>
    <?php endforeach; ?>
    </select>
</div>
<?php endif; ?>

Links to Magento API docs for the methods used:

Thursday, February 11, 2016

Magento: Delete All Products & Categories via SQL

FOR PRODUCTS

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`;FOR CATEGORY
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`;
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');




FOR CATEGORY
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE `catalog_category_entity`;
TRUNCATE TABLE `catalog_category_entity_datetime`;
TRUNCATE TABLE `catalog_category_entity_decimal`;
TRUNCATE TABLE `catalog_category_entity_int`;
TRUNCATE TABLE `catalog_category_entity_text`;
TRUNCATE TABLE `catalog_category_entity_varchar`;
TRUNCATE TABLE `catalog_category_product`;
TRUNCATE TABLE `catalog_category_product_index`;
 
INSERT INTO `catalog_category_entity`
  (`entity_id`,`entity_type_id`,`attribute_set_id`,`parent_id`,`created_at`,`updated_at`,`path`,`POSITION`,`level`,`children_count`)
VALUES
  (1,3,0,0,'0000-00-00 00:00:00','2009-02-20 00:25:34','1',1,0,1),
  (2,3,3,0,'2009-02-20 00:25:34','2009-02-20 00:25:34','1/2',1,1,0);

INSERT INTO `catalog_category_entity_int`
  (`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`)
VALUES
  (1,3,32,0,2,1),
  (2,3,32,1,2,1);

INSERT INTO `catalog_category_entity_varchar`
  (`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`)
VALUES
  (1,3,31,0,1,'Root Catalog'),
  (2,3,33,0,1,'root-catalog'),
  (3,3,31,0,2,'Default Category'),
  (4,3,39,0,2,'PRODUCTS'),
  (5,3,33,0,2,'default-category');
SET FOREIGN_KEY_CHECKS = 1;

Tuesday, February 9, 2016

Get Order Details from Order ID in Magento

In Magento quite often you need to get order details from order ID. So in this tutorial I am going to show you how to get order details from order ID. There are two types of order ID’s, one is real order ID and the other is order increment ID. So first I will let you know how to get real order ID from order increment ID.

To Get real order ID from order increment id in Magento:
let’s assume your order increment id is #10001222 and you need to get real order ID, you can use following code:

$orderIncrementId = 10001222;
$orderId = Mage::getModel('sales/order')
             ->loadByIncrementId($orderIncrementId)
             ->getEntityId();

You can get order details by order increment ID as follow:
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);

If you know the real order ID you can get order details by using following code:
$order = Mage::getModel("sales/order")->load($orderId);

To get order total value:
$orderTotalValue = number_format ($order->getGrandTotal(), 2, '.' , $thousands_sep = '');

To get order items collection:

$orderItems = $order->getItemsCollection();
foreach ($orderItems as $item){

    $product_id = $item->product_id;
    $product_sku = $item->sku;
    $product_price = $item->getPrice();
    $product_name = $item->getName();
    $_product = Mage::getModel('catalog/product')->load($product_id);
    $cats = $_product->getCategoryIds();
    $category_id = $cats[0]; // just get the first id
    $category = Mage::getModel('catalog/category')->load($category_id);
    $category_name = $category->getName();
}

To get shipping method from order:
$shipping_method = $order->getShippingMethod();

To get payment method code from order you can use following code:
$payment_method_code = $order->getPayment()->getMethodInstance()->getCode();

I hope this tutorial will help you to get order details from order ID in Magento.

Tuesday, January 12, 2016

Get Filterable attribute by Category ID

<?php
$category_ids = $this->getCategoryid(); // HERE YOU CAN PUT THE STATIC CATEGORY ID

$layer = Mage::getModel("catalog/layer");
    $categoryid = $category_ids;
    $category = Mage::getModel("catalog/category")->load($categoryid);
    $layer->setCurrentCategory($category);
    $attributes = $layer->getFilterableAttributes();

    foreach ($attributes as $attribute) {
        if ($attribute->getAttributeCode() != 'price') {
           
            $filterBlockName = 'catalog/layer_filter_attribute';
       
        echo '<br/>---'.$attribute->getFrontendLabel();
        echo '---<br/>';
        $result = $this->getLayout()->createBlock($filterBlockName)->setLayer($layer)
->setAttributeModel($attribute)->init();
       
        foreach($result->getItems() as $option) {
            echo $option->getLabel().'<br/>';
            echo $option->getValue();
        }
        }
}

?>

Thursday, January 7, 2016

How to override controller in magento/Override controller’s action in magento

Some times you may run into situation where you want to override the core functionality of Magento core controllers.

So in this case, The best practise is override the controller then override actions or add new actions for custom requirement.

For example you want to override OnepageController.php file and overwride indexAction.

In this example my custom module name space is “MyBlog” and i am going to overwride indexAction

Mage_Checkout_OnepageController


Base File Path : app/code/core/Mage/Checkout/controllers/OnepageController.php
To Do the same we have to follow bellow steps.

Step1: We need to create a custom module


File Path : app/etc/modules/
File Name: MyBlog_Checkout.xml
File Content:

<?xml version="1.0"?>
<config>
<modules>
<MyBlog_Checkout>
<active>true</active>
<codePool>local</codePool>
</MyBlog_Checkout>
</modules>
</config>
Step2: Now we have to create bellow files in our custom module


File Path: app/code/local/MyBlog/Checkout/etc/config.xml
Bellow is content for config.xml file

<?xml version="1.0"?>
<config>
<modules>
<MyBlog_Checkout>
<version>0.0.1</version>
</MyBlog_Checkout>
</modules>
<frontend>
<routers>
<checkout>
<args>
<modules>
<MyBlog_Checkout before="Mage_Checkout">MyBlog_Checkout</MyBlog_Checkout>
</modules>
</args>
</checkout>
</routers>
</frontend>
</config>
Bellow is content for OnepageController.php


File Path : app/code/local/MyBlog/Checkout/controllers/OnepageController.php

<?php
require_once 'Mage/Checkout/controllers/OnepageController.php';

class MyBlog_Checkout_OnepageController extends Mage_Checkout_OnepageController {

public function indexAction()
{
echo "Great! You are in MyBlog checkout controller section";
exit;
}
}
?>

Wednesday, December 30, 2015

Fixing Magento Catalog Price Rules Issue

try {
Mage::getConfig()->init()->loadEventObservers('crontab');
Mage::app()->addEventArea('crontab');
Mage::dispatchEvent('default');
$observ = Mage::getModel('catalogrule/observer');
$observ->dailyCatalogUpdate("0 1 * * *");
} catch (Exception $e) {
Mage::printException($e);
}