пятница, 28 сентября 2012 г.

Magento HowTo. Part1

How to

  • Enable/Disable Reviews
    • Manually in Backend
      • System->Configuration->Advanced:Advanced->Disable Modules Output->Mage_Review
        • Enable/Disable
    • In the code (code example):
      • $store = Mage::app()->getStore('davitamon');
      • Mage::getModel('core/config')->saveConfig('advanced/modules_disable_output/Mage_Review', '0' , 'stores', $store->getId());


четверг, 6 сентября 2012 г.

Using readline with Oracle SQL*Plus

This is repost of the following link:
http://blog.cachemiss.com/articles/Using%20readline%20with%20Oracle%20SQL*Plus.pod



By default, Oracle's SQL*Plus has no support for history, command line editing, etc.

This problem can be solved with the rlwrap utility. There is a Debian package, or you can easily compile it for any system.

Source is here: http://utopia.knoware.nl/~hlub/rlwrap/.

Once installed, add this alias to your .bashrc:

alias sqlplus="rlwrap -i -f ~/.sqlplus_history -H ~/.sqlplus_history -s 30000 sqlplus"

This defines a history file and uses it as your completion wordlist, and sets the history size to 30000 entries.

Before running it for the first time, do a:

touch ~/.sqlplus_history

That's all there is to it, and now you have readline support in your SQL*Plus!

How to create a new website/store/storeview in Magento (code snippet)

This is an example of install/upgrade script for creating a new website/store/storeview in Magento.
Also prefixes for order/invoice/shipment numbers are set.


<?php>
try {

    $websiteName = 'Website Name';
    $websiteCode = 'website_code';
    $storeName = 'Store Name';
    $storeViewName = 'Store View Name';
    //$rootCategoryName = 'Website Name Root Category';


    /** @var $installer Mage_Catalog_Model_Resource_Setup */
    $installer = $this;

    /** @var $write Zend_Db_Adapter_Abstract */
    $write = Mage::getSingleton('core/resource')->getConnection('core_write');

    $write->beginTransaction();

//    // Create root category
//    /**  @var Mage_Catalog_Model_Category $rootCategory */
//    $rootCategory = Mage::getModel('catalog/category');
//    $rootCategory->setName($rootCategoryName)
//        ->setDisplayMode('PRODUCTS')
//        ->setIsActive(1)
//        ->setPath('1')
//        ->setStoreId(0)
//    ;
//    //$rootCategory->setThumbnail(null);
//
//    $rootCategory->save();


    // Create website
    /** @var Mage_Core_Model_WebsiРte $website */
    $website = Mage::getModel('core/website');
    $website
        ->setName($websiteName)
        ->setCode($websiteCode)
        ->save();

    // Create Store
    /** @var Mage_Core_Model_Store_Group $store  */
    $store = Mage::getModel('core/store_group');
    $store
        ->setWebsiteId($website->getId())
        ->setName($storeName)
        // Error happened 'exception 'Exception' with message '$_FILES array is empty' in src/lib/Varien/File/Uploader.php:467' when this line is uncommented.
        //->setRootCategoryId($rootCategory->getId())
        ->save();

    // Set relations to Store in Website
    $website->setDefaultGroupId($store->getId());


    // Crate Store View
    /** @var Mage_Core_Model_Store $storeView  */
    $storeView = Mage::getModel('core/store');
    $storeView
        ->setName($storeViewName)
        ->setCode($websiteCode)
        ->setWebsiteId($website->getId())
        ->setGroupId($store->getId())
        ->setIsActive(1)
        ->save();

    // Set relations to StoreView in Store.
    $store->setDefaultStoreId($storeView->getId());
    /** @var $config Mage_Core_Model_Config */
    $config = Mage::getModel('core/config');

    // Set store name
    $config->saveConfig(Mage_Core_Model_Store::XML_PATH_STORE_STORE_NAME, $websiteName, 'stores', $storeView->getId());


    // Add prefix for orders (5), invoices(6), shipments(8)
    $write->query("
        insert into `eav_entity_store` (entity_type_id, store_id, increment_prefix, increment_last_id)
        values
        (5, {$storeView->getId()}, 3, 300000000),
        (6, {$storeView->getId()}, 3, 300000000),
        (8, {$storeView->getId()}, 3, 300000000)
    ");

    $write->commit();

} catch (Exception $e) {
    $write->rollback();
    Mage::throwException($e);
}