Monday, January 18, 2016

Adding CMS Static Block to Footer

Add following content on local.xml


<layout>
    <default>
        <reference name="head">
            <action method="addItem">
              <type>skin_js</type><name>js/ism/string-truncate.js</name>
           </action>
        </reference>
        <reference name="footer">
            <block type="cms/block" name="footer_shipping_icon" as="footer_shipping_icon">
                <action method="setBlockId">
                    <block_id>footer_shipping_icon</block_id>
                </action>
            </block>
        </reference>
    </default>
</layout>
Call the CMS/Block on PHTML file. (ex: footer.phtml)
<div class="footer-shipping-icon">
    <?php echo $this->getChildHtml('footer_shipping_icon'); ?></div>

Wednesday, January 13, 2016

Delete Product Attribute Programatically

<?phpdefine('MAGENTO_ROOT', getcwd());
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
Mage::app();

echo "Begining...."."\n";
try{
$model = new Mage_Eav_Model_Entity_Setup('core_setup');
// your attribute code here
$attribute_id = 'salelabel'
// Remove Product Attribute
$model->removeAttribute('catalog_product', $attribute_id);
echo "Done"."\n";
}catch(Exception $e)
{
  echo "An exception occured.".$e->getMessage();      
}
echo "Ending...."."\n";

Download File Remotely

<?php /* Download a file remotely */$target_file = "/home/ism-apac/Desktop/Test/test.jpg";
$url = "https://nthm3.s3.amazonaws.com/catalog/o/48631a.jpg";

try{
file_put_contents($target_file, fopen($url, 'r'));
}
catch(Exception $e)
{
  echo $e->getMessage();
}
?>

Re-index Magento via SSH

How to do:
1. Login to Server using SSH
> pwd
> ls -al

2. Move to ROOT/shell folder
> cd shell/
> ls -al

3. Get help from “indexer.php” script
> php -f indexer.php help

4. Get the list of indexers which you can execute
> php -f indexer.php info

Ex:
catalog_product_attribute     Product Attributes
catalog_product_price         Product Prices
//===============================================
catalog_url                   Catalog Url Rewrites
//===============================================
catalog_product_flat          Product Flat Data
catalog_category_flat         Category Flat Data
catalog_category_product      Category Products
catalogsearch_fulltext        Catalog Search Index
cataloginventory_stock        Stock status

cataloginventory_stock        Stock Status
catalog_product_price         Catalog product price
catalog_url_category          Category URL Rewrites
catalog_url_product           Product URL Rewrites
//===============================================
url_redirect                  URL Redirects
//===============================================
catalog_category_product      Catalog Category/Product Index
catalogsearch_fulltext        Catalog Search Index
tag_summary                   Tag Aggregation Data
catalog_product_attribute     Product Attributes


5. you can reindex any of the indexers one by one.
> php indexer.php --reindex   <<reindexer_name>>
Ex:
> php indexer.php --reindex catalog_url_category

6. If you want to reindex everything at once, use the below command
> php indexer.php -reindexall

Run Magento Cron programatically

<?php
define('MAGENTO_ROOT', getcwd());
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
Mage::app();

echo "Begining...."."\n";
try{
$observer = Mage::getModel("ism_import/cron_stock");
$vall = $observer->importStock();
print_r($vall);
}catch(Exception $e)
{
  echo "An exception occured.".$e->getMessage();      
}
echo "Ending...."."\n";

Install Script to add Product "Drop down" attribute

<?php
/* @var $model Mage_Eav_Model_Entity_Setup */$model = Mage::getModel('eav/entity_setup','core_setup');

$model->startSetup();

$data = array(
    'type'              =>  'varchar',
    'input'             =>  'select',
    'label'             =>  'Sale Label',
    'global'            =>  Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE,
    'required'          =>  '0',
    'comparable'        =>  '0',
    'searchable'        =>  '0',
    'is_unique'         =>  '1',
    'is_configurable'   =>  '1',
    'user_defined'      =>  true,
    'group'             =>  'Kixx online',
    'attribute_set'     =>  'Producten');

$model->addAttribute('catalog_product', 'salelabel', $data);


$attributeId        =   $model->getAttribute('catalog_product','salelabel');
$attributeSetId     =   $model->getAttributeSetId('catalog_product','Producten');
/** Get attribute group info */$attributeGroupId   =   $model->getAttributeGroup('catalog_product',$attributeSetId,'Kixx online');
/** Add attribute to a set */$model->addAttributeToSet('catalog_product',$attributeSetId,$attributeGroupId,$attributeId);

$model->endSetup();

Set Base Image on Thumbnail Image

<?php
require_once '../app/Mage.php';

Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
Mage::app('admin');

Mage::register('isSecureArea', 1);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

set_time_limit(0);
ini_set('memory_limit','1024M');

$connection = Mage::getSingleton('core/resource')->getConnection('core_write');

$sqlSp = "select entity_id from catalog_product_entity_varchar where `value` like '%https:%' and attribute_id = 87";
$res = $connection->fetchAll($sqlSp);

foreach ($res as $v) {
    $entityID = $v["entity_id"];
    $sqlURL = "select `value` from catalog_product_entity_varchar where entity_id = ? and attribute_id = 86";
    $url = $connection->fetchOne($sqlURL, $entityID);
    echo $entityID . " - " . $url . PHP_EOL;
    $sqlUpdte = "UPDATE catalog_product_entity_varchar SET `value` = ? where entity_id = ? and attribute_id = 87";
    $connection->query($sqlUpdte, array($url, $entityID));
}