-
-
Save tuanphpvn/580a8ccb45b33ac9b3ba to your computer and use it in GitHub Desktop.
Revisions
-
quafzi revised this gist
Apr 16, 2013 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -610,16 +610,16 @@ echo $product->getId(); // ID = 462 (aka, Parent of 465) ## Block Caching `getCacheLifetime`: cache lifetime * 0 = unlimited * false = unlimited * null = no caching * any other integer value = cache lifetime in seconds `getCacheKeyInfo`: array of values, the cache depends on `getCacheTags`: array of values to segment the cache * default value: `array('block_html')` * example: `array('block_html', 'navi')`, after that you could clean your cache partially: `Mage::app()->cleanCache(array(‘navi’))` -
quafzi revised this gist
Apr 16, 2013 . 1 changed file with 0 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +0,0 @@ -
quafzi revised this gist
Apr 16, 2013 . No changes.There are no files selected for viewing
-
quafzi revised this gist
Apr 16, 2013 . 2 changed files with 84 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ <block type="cms/block" name="block_name"> <action method="setBlockId"><id>block_code</id></action> </block> {{block type="cms/block" block_id="block_code"}} {{block type="catalog/product_list" category_id="79" template="catalog/product/list_random.phtml"}} This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -158,6 +158,61 @@ Normally, the getChildHtml method is used to render a specific child block. Howe to `page.xml`, and then add the `mytemplate.phtml` file. Any block added to the head block will be automatically rendered. (this automatic rendering doesn't apply for all layout blocks, only for blocks where getChildHtml is called without paramaters). ## Programmatically update the layout from av event ## @author moleman gist from from git://gist.github.com/1723022.git config.xml ```xml <frontend> <events> <controller_action_layout_generate_xml_before> <observers> <rimpachidecategories> <type>singleton</type> <class>rimpachidecategories/observer</class> <method>onControllerActionLayoutGenerateXmlBefore</method> </rimpachidecategories> </observers> </controller_action_layout_generate_xml_before> </events> </frontend> ``` PHP method: ```php <?php /** * Method that will be called when the controller_action_layout_generate_xml_before event is fired. * Adds layout update that removes catalog.topnav depending on if the hide categories attribute is * toggle on the logged in customer object. * * @see Mage_Core_Controller_Varien_Action::generateLayoutXml() * @param Varien_Event_Observer $observer */ public function onControllerActionLayoutGenerateXmlBefore($observer) { /* @var $action Mage_Core_Controller_Varien_Action */ $action = $observer->getEvent()->getAction(); /* @var $layout Mage_Core_Model_Layout */ $layout = $observer->getEvent()->getLayout(); /* @var $session Mage_Customer_Model_Session */ $session = Mage::getSingleton('customer/session'); if (!is_null($session) && $session->isLoggedIn() === true && $session->getCustomer()->getData('ic_hide_toggle')) { $layout->getUpdate()-> addUpdate('<reference name="top.menu"><remove name="catalog.topnav" /></reference>'); } } ?> ``` ## Check if customer is logged in ## ```php @@ -843,3 +898,25 @@ private function _attachProductToConfigurable( $_childProduct, $_configurablePro $loader->saveProducts( $_configurableProduct->getId(), array_keys( $newids ) ); } ``` ## Add Options to ERP Attributes from Code/Installer scripts ## ```php <?php $installer = Mage::getModel('eav/entity_setup', 'core_setup'); $options = array(); $options['value']['option_1'][0] = 'RED 2'; $options['attribute_id'] = $installer->getAttributeId('catalog_product', 'color'); $installer->addAttributeOption($options); ?> ``` ## Admin set filters on redirect from controller action code ## Redirect to Order Grid with search filter set from controller action code ```php <?php $filter_params = array('sort' => 'created_at', 'dir' => 'desc', 'filter' => base64_encode('real_order_id='.$orig_order_original_increment_id)); $this->_redirect('*/sales_order/index', $filter_params); ?> ``` -
quafzi revised this gist
Apr 16, 2013 . 1 changed file with 286 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,62 @@ # Magento Snippets # ## Find all dispatched event observers ## ``` grep -r Mage::dispatchEvent /path/to/your/Magento/* > events.txt ``` ## Find all translatable strings ## ``` grep -shR "\->__('" *|sed "s/\(;|?>\)/\1\n/g;s/^[ \t]*//;s/[ \t]*$//;s/.*->__('\([^']\+\)'[^)]*).*/\1/g" ``` ## Export database with mysqldump minus log tables ## Example: (with tables to ignore from Magento minus usual stuff like -u -p etc.) ```sql mysqldump --ignore-table=db.log_customer -–ignore-table=db.log_quote -–ignore=db.log_summary –-ignore=db.log_summary_type –-ignore=db.log_url -–ignore=db.log_url_info -–ignore=db.log_visitor -–ignore=db.log_visitor_info --ignore=db.log_visitor_online –-ignore=db.log_summary –-ignore=db.enterprise_logging_event –-ignore=db.enterprise_logging_event_changes ``` Notes: - replace db. with your databasename and remove enterprise tables if community edition. - http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_ignore-table ## Download extension manually using pear/mage ## Pear for 1.4, mage for 1.5. File downloaded into /downloader/.cache/community/ ./pear download magento-community/Shipping_Agent ./mage download community Shipping_Agent ## Download Archived extension manually without pear/mage ## If for some reason you need to download a Magento Connect extension archive from command line, use the following : wget http://connect.magentocommerce.com/TYPE/get/EXTENSION_NAME-X.X.X.tgz TYPE must be replaced with real extension type(usually core or community), EXTENSION_NAME with real(machine readable) extension name and X.X.X must be replaced with the real version number. To retrieve real TYPE and the real machine readable EXTENSION_NAME simply look at it’s extension key and take into a count it’s format magento-TYPE/EXTENSION_NAME. For example: http://www.magentocommerce.com/extension/518/blank-theme Extension key: magento-core/Interface_Frontend_Default_Blank Version(at the time of writing): 1.4.1.1 Download URL: wget http://connect.magentocommerce.com/core/get/Interface_Frontend_Default_Blank-1.4.1.1.tgz Other example: http://www.magentocommerce.com/extension/974/yoast-blank-seo-theme Extension key: magento-community/Yoast_Blank_Seo_Theme Version(at the time of writing): 1.4.1 Download URL: wget http://connect.magentocommerce.com/community/get/Yoast_Blank_Seo_Theme-1.4.1.tgz ## Clear cache/reindex ## ```php @@ -557,3 +608,238 @@ $order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('ch ->load(); ?> ``` ## Log all layout updates ## ```php //Full path to the log file: $logPath = Mage::getConfig()->getOptions()->getVarDir().DS.$file_name.time().'.xml'; //Layout model: Mage_Core_Model_Layout $layout = Mage::getSingleton('core/layout'); //Generate our xml with Mage_Core_Layout_Update model and save it in a file $xml = '<'.'?xml version="1.0"?'.'>'; $xml .= '<layout>'.trim($layout->getUpdate()->asString()).'</layout>'; file_put_contents($logPath, $xml); ``` ## Defining configuration in xml files (local.xml), instead of db ## ```xml <config> <stores> <store_code> <!-- config value for a store (web/unsecure/base_url) --> <web> <unsecure> <base_url>http://example-magento-store.com</base_url> </unsecure> </web> </store_code> </stores> <websites> <website_code> <!-- config value for a website (web/unsecure/base_url) --> <web> <unsecure> <base_url>http://another-example-magento-store.com</base_url> </unsecure> </web> </website_code> </websites> <default> <!-- default config value (web/unsecure/base_url) --> <web> <unsecure> <base_url>http://default-magento-store.com</base_url> </unsecure> </web> </default> </config> ``` ## Clean re-integration of console.log in Chrome for Magento ## ```xml <default> <reference name="content"> <block type="core/text" name="fix.console" as="fix.console"> <action method="setText"> <text><![CDATA[<script type="text/javascript"> iframe = document.createElement('iframe'); iframe.style.display = 'none'; document.getElementsByTagName('body')[0].appendChild(iframe); window.console = iframe.contentWindow.console; console.firebug = "faketrue"; </script>]]></text> </action> </block> </reference> </default> ``` ## Disable local modules ## ```xml <disable_local_modules>true</disable_local_modules> ``` ## Working with Mage_Core_Model_Cache ## ```php // Save $cache->save(date("r"), "nick_date", array("nicks_cache"), 10); $cache->save("hello world - " . time(), "nick_helloworld", array("nicks_cache"), 60*60); // Load $cache->load("nick_date"); // Remove $cache->remove("nick_date"); // Flush group $cache->flush("nicks_cache"); ``` ## Magento Notifications types ## ```php /* There are few 'notification types' in Magento you can utilize: */ // error: Mage::getSingleton('core/session')->addError('Custom error here'); // warning: Mage::getSingleton('core/session')->addWarning('Custom warning here'); // notice: Mage::getSingleton('core/session')->addNotice('Custom notice here'); // success: Mage::getSingleton('core/session')->addSuccess('Custom success here'); ``` ## If is homepage ## ```php $routeName = Mage::app()->getRequest()->getRouteName(); $identifier = Mage::getSingleton('cms/page')->getIdentifier(); if($routeName == 'cms' && $identifier == 'home') { echo 'You are in Homepage!'; } else { echo 'You are NOT in Homepage!'; } ``` ## Delete ALL Customers ## ``` sql SET FOREIGN_KEY_CHECKS=0; -- reset customers TRUNCATE customer_address_entity; TRUNCATE customer_address_entity_datetime; TRUNCATE customer_address_entity_decimal; TRUNCATE customer_address_entity_int; TRUNCATE customer_address_entity_text; TRUNCATE customer_address_entity_varchar; TRUNCATE customer_entity; TRUNCATE customer_entity_datetime; TRUNCATE customer_entity_decimal; TRUNCATE customer_entity_int; TRUNCATE customer_entity_text; TRUNCATE customer_entity_varchar; TRUNCATE log_customer; TRUNCATE log_visitor; TRUNCATE log_visitor_info; ALTER TABLE customer_address_entity AUTO_INCREMENT=1; ALTER TABLE customer_address_entity_datetime AUTO_INCREMENT=1; ALTER TABLE customer_address_entity_decimal AUTO_INCREMENT=1; ALTER TABLE customer_address_entity_int AUTO_INCREMENT=1; ALTER TABLE customer_address_entity_text AUTO_INCREMENT=1; ALTER TABLE customer_address_entity_varchar AUTO_INCREMENT=1; ALTER TABLE customer_entity AUTO_INCREMENT=1; ALTER TABLE customer_entity_datetime AUTO_INCREMENT=1; ALTER TABLE customer_entity_decimal AUTO_INCREMENT=1; ALTER TABLE customer_entity_int AUTO_INCREMENT=1; ALTER TABLE customer_entity_text AUTO_INCREMENT=1; ALTER TABLE customer_entity_varchar AUTO_INCREMENT=1; ALTER TABLE log_customer AUTO_INCREMENT=1; ALTER TABLE log_visitor AUTO_INCREMENT=1; ALTER TABLE log_visitor_info AUTO_INCREMENT=1; SET FOREIGN_KEY_CHECKS=1; ``` ## Create Order Programmatically ## ```php <?php require_once 'app/Mage.php'; Mage::app(); $quote = Mage::getModel('sales/quote') ->setStoreId(Mage::app()->getStore('default')->getId()); if ('do customer orders') { // for customer orders: $customer = Mage::getModel('customer/customer') ->setWebsiteId(1) ->loadByEmail('[email protected]'); $quote->assignCustomer($customer); } else { // for guesr orders only: $quote->setCustomerEmail('[email protected]'); } // add product(s) $product = Mage::getModel('catalog/product')->load(8); $buyInfo = array( 'qty' => 1, // custom option id => value id // or // configurable attribute id => value id ); $quote->addProduct($product, new Varien_Object($buyInfo)); $addressData = array( 'firstname' => 'Test', 'lastname' => 'Test', 'street' => 'Sample Street 10', 'city' => 'Somewhere', 'postcode' => '123456', 'telephone' => '123456', 'country_id' => 'US', 'region_id' => 12, // id from directory_country_region table ); $billingAddress = $quote->getBillingAddress()->addData($addressData); $shippingAddress = $quote->getShippingAddress()->addData($addressData); $shippingAddress->setCollectShippingRates(true)->collectShippingRates() ->setShippingMethod('flatrate_flatrate') ->setPaymentMethod('checkmo'); $quote->getPayment()->importData(array('method' => 'checkmo')); $quote->collectTotals()->save(); $service = Mage::getModel('sales/service_quote', $quote); $service->submitAll(); $order = $service->getOrder(); printf("Created order %s\n", $order->getIncrementId()); ``` ## Assign/Unassign (merge) list of simple productids to existing configurable product ## ```php private function _attachProductToConfigurable( $_childProduct, $_configurableProduct ) { $loader = Mage::getResourceModel( 'catalog/product_type_configurable' )->load( $_configurableProduct ); $ids = $_configurableProduct->getTypeInstance()->getUsedProductIds(); $newids = array(); foreach ( $ids as $id ) { $newids[$id] = 1; } $newids[$_childProduct->getId()] = 1; $loader->saveProducts( $_configurableProduct->getId(), array_keys( $newids ) ); } ``` -
quafzi revised this gist
Apr 16, 2013 . 1 changed file with 43 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -162,6 +162,7 @@ Clear your cache and sessions. By default, Magento will check the 'Exclude' box for you on all imported images, making them not show up as a thumbnail under the main product image on the product view. ```sql # Mass Unexclude UPDATE`catalog_product_entity_media_gallery_value` SET `disabled` = '0' WHERE `disabled` = '1'; # Mass Exclude @@ -514,5 +515,45 @@ getCacheKeyInfo: array of values, the cache depends on getCacheTags: array of values to segment the cache * default value: `array('block_html')` * example: `array('block_html', 'navi')`, after that you could clean your cache partially: `Mage::app()->cleanCache(array(‘navi’))` ## Get last order from checkout ## ```php <?php $order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId()); ?> ``` ## Get order and product information ## ```php <?php //$order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId()); $order = Mage::getModel('sales/order')->loadByIncrementId(100000001); foreach ($order->getItemsCollection() as $item) { //load the product from the order $product = Mage::getModel('catalog/product')->load($item->getData('product_id')); //loop trhough ignoring any configurables if($product->getTypeId() == 'simple') { echo $product->getData('licence_qty'); } } ?> ``` ## Filter Custom (non eav) Collection ## ```php <?php ->getCollection() ->addFieldToFilter('code', array('eq' => $licenceCodeIn)) ->load(); ?> ``` -
quafzi revised this gist
Apr 16, 2013 . 1 changed file with 17 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -499,4 +499,20 @@ $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable') $product = Mage::getModel('catalog/product')->load($parentIds[0]); echo $product->getId(); // ID = 462 (aka, Parent of 465) ?> ``` ## Block Caching getCacheLifetime: cache lifetime * 0 = unlimited * false = unlimited * null = no caching * any other integer value = cache lifetime in seconds getCacheKeyInfo: array of values, the cache depends on getCacheTags: array of values to segment the cache * default value: ```array('block_html')``` * example: ```array('block_html', 'navi')```, after that you could clean your cache partially: ```Mage::app()->cleanCache(array(‘navi’))``` -
codethis revised this gist
Feb 9, 2013 . 1 changed file with 22 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -508,6 +508,28 @@ echo $product->getId(); // ID = 462 (aka, Parent of 465) $order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId()); ?> ``` ## Get order and product information ## ```php <?php //$order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId()); $order = Mage::getModel('sales/order')->loadByIncrementId(100000001); foreach ($order->getItemsCollection() as $item) { //load the product from the order $product = Mage::getModel('catalog/product')->load($item->getData('product_id')); //loop trhough ignoring any configurables if($product->getTypeId() == 'simple') { echo $product->getData('licence_qty'); } } ?> ``` ## Filter Custom (non eav) Collection ## -
codethis revised this gist
Feb 9, 2013 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -507,4 +507,14 @@ echo $product->getId(); // ID = 462 (aka, Parent of 465) <?php $order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId()); ?> ``` ## Filter Custom (non eav) Collection ## ```php <?php ->getCollection() ->addFieldToFilter('code', array('eq' => $licenceCodeIn)) ->load(); ?> ``` -
codethis revised this gist
Feb 9, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -501,10 +501,10 @@ echo $product->getId(); // ID = 462 (aka, Parent of 465) ?> ``` ## Get last order from checkout ## ```php <?php $order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId()); ?> ``` -
codethis revised this gist
Feb 2, 2013 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -499,4 +499,12 @@ $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable') $product = Mage::getModel('catalog/product')->load($parentIds[0]); echo $product->getId(); // ID = 462 (aka, Parent of 465) ?> ``` ## Test ## ```php <?php $_category = Mage::getModel('catalog/category')->load(89); ?> ``` -
molotovbliss revised this gist
Nov 27, 2012 . 1 changed file with 17 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -768,4 +768,21 @@ $service->submitAll(); $order = $service->getOrder(); printf("Created order %s\n", $order->getIncrementId()); ``` ## Assign/Unassign (merge) list of simple productids to existing configurable product ## ```php private function _attachProductToConfigurable( $_childProduct, $_configurableProduct ) { $loader = Mage::getResourceModel( 'catalog/product_type_configurable' )->load( $_configurableProduct ); $ids = $_configurableProduct->getTypeInstance()->getUsedProductIds(); $newids = array(); foreach ( $ids as $id ) { $newids[$id] = 1; } $newids[$_childProduct->getId()] = 1; $loader->saveProducts( $_configurableProduct->getId(), array_keys( $newids ) ); } ``` -
claudiu-marginean revised this gist
Oct 1, 2012 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -567,4 +567,14 @@ $options['value']['option_1'][0] = 'RED 2'; $options['attribute_id'] = $installer->getAttributeId('catalog_product', 'color'); $installer->addAttributeOption($options); ?> ``` ## Admin set filters on redirect from controller action code ## Redirect to Order Grid with search filter set from controller action code ```php <?php $filter_params = array('sort' => 'created_at', 'dir' => 'desc', 'filter' => base64_encode('real_order_id='.$orig_order_original_increment_id)); $this->_redirect('*/sales_order/index', $filter_params); ?> ``` -
claudiu-marginean revised this gist
Aug 3, 2012 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -554,4 +554,17 @@ $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable') $product = Mage::getModel('catalog/product')->load($parentIds[0]); echo $product->getId(); // ID = 462 (aka, Parent of 465) ?> ``` ## Add Options to ERP Attributes from Code/Installer scripts ## ```php <?php $installer = Mage::getModel('eav/entity_setup', 'core_setup'); $options = array(); $options['value']['option_1'][0] = 'RED 2'; $options['attribute_id'] = $installer->getAttributeId('catalog_product', 'color'); $installer->addAttributeOption($options); ?> ``` -
molotovbliss revised this gist
Jul 17, 2012 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,11 @@ # Magento Snippets # ## Find all dispatched event observers ## ``` grep -r Mage::dispatchEvent /path/to/your/Magento/* > events.txt ``` ## Find all translatable strings ## ``` -
molotovbliss revised this gist
Jul 17, 2012 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,11 @@ # Magento Snippets # ## Find all translatable strings ## ``` grep -shR "\->__('" *|sed "s/\(;|?>\)/\1\n/g;s/^[ \t]*//;s/[ \t]*$//;s/.*->__('\([^']\+\)'[^)]*).*/\1/g" ``` ## Export database with mysqldump minus log tables ## Example: (with tables to ignore from Magento minus usual stuff like -u -p etc.) -
molotovbliss revised this gist
Jul 17, 2012 . 1 changed file with 0 additions and 83 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,88 +1,5 @@ # Magento Snippets # ## Export database with mysqldump minus log tables ## Example: (with tables to ignore from Magento minus usual stuff like -u -p etc.) -
molotovbliss revised this gist
Jul 5, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ Source: http://narno.com/blog/verifier-la-validite-des-fichiers-de-configuration app/code/local/Varien/Simplexml/Config.php : ``` php <?php class Varien_Simplexml_Config { /** -
molotovbliss revised this gist
Jul 5, 2012 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ app/code/local/Varien/Simplexml/Config.php : ``` php class Varien_Simplexml_Config { /** * Imports XML file * @@ -79,7 +79,7 @@ class Varien_Simplexml_Config { } return false; } } ``` -
molotovbliss revised this gist
Jul 5, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Magento Snippets # ## Enable a means to help verify Magento XML configuration files validness ## Source: http://narno.com/blog/verifier-la-validite-des-fichiers-de-configuration-xml-de-magento -
molotovbliss revised this gist
Jul 5, 2012 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,8 +2,10 @@ ## Enable a means to help verify Magento MXL configuration files validness ## Source: http://narno.com/blog/verifier-la-validite-des-fichiers-de-configuration-xml-de-magento app/code/local/Varien/Simplexml/Config.php : ``` php class Varien_Simplexml_Config { [...] -
molotovbliss revised this gist
Jul 5, 2012 . 1 changed file with 81 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,86 @@ # Magento Snippets # ## Enable a means to help verify Magento MXL configuration files validness ## ``` php app/code/local/Varien/Simplexml/Config.php : class Varien_Simplexml_Config { [...] /** * Imports XML file * * @param string $filePath * @return boolean */ public function loadFile($filePath) { if (!is_readable($filePath)) { //throw new Exception('Can not read xml file '.$filePath); return false; } $fileData = file_get_contents($filePath); $fileData = $this->processFileData($fileData); /** * Custom code: $filePath added */ // original //return $this->loadString($fileData, $this->_elementClass); // new return $this->loadString($fileData, $this->_elementClass, $filePath); } /** * Imports XML string * * @param string $string * @return boolean */ public function loadString($string) { if (is_string($string)) { /** * Custom code: dealing with config file XML errors */ libxml_use_internal_errors(true); $xmlcheck = simplexml_load_string($string); if (!is_object($xmlcheck)) { $argslist = func_get_args(); $filePath = $argslist[2]; foreach(libxml_get_errors() as $error) { $error = array( 'message' => trim($error->message), 'code' => 'Code: ' . $error->code, 'file' => 'File: ' . ($error->file != '' ? $error->file : $filePath), 'line' => 'Line: ' . $error->line, 'column' => 'Column: ' . $error->column, ); } libxml_clear_errors(); // log Mage::log("\n" . implode("\n", $error), Zend_Log::ERR, 'exception_config.log'); // throw in developer mode if (Mage::getIsDeveloperMode()) { Mage::printException(new Exception(implode("\n", $error)), 'CONFIG FILE ERROR'); } } // /Custom code $xml = simplexml_load_string($string, $this->_elementClass); if ($xml instanceof Varien_Simplexml_Element) { $this->_xml = $xml; return true; } } else { Mage::logException(new Exception('"$string" parameter for simplexml_load_string is not a string')); } return false; } [...] } ``` ## Export database with mysqldump minus log tables ## Example: (with tables to ignore from Magento minus usual stuff like -u -p etc.) -
molotovbliss revised this gist
Jun 26, 2012 . 1 changed file with 62 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -694,4 +694,66 @@ ALTER TABLE log_customer AUTO_INCREMENT=1; ALTER TABLE log_visitor AUTO_INCREMENT=1; ALTER TABLE log_visitor_info AUTO_INCREMENT=1; SET FOREIGN_KEY_CHECKS=1; ``` ## Create Order Programmatically ## ```php <?php require_once 'app/Mage.php'; Mage::app(); $quote = Mage::getModel('sales/quote') ->setStoreId(Mage::app()->getStore('default')->getId()); if ('do customer orders') { // for customer orders: $customer = Mage::getModel('customer/customer') ->setWebsiteId(1) ->loadByEmail('[email protected]'); $quote->assignCustomer($customer); } else { // for guesr orders only: $quote->setCustomerEmail('[email protected]'); } // add product(s) $product = Mage::getModel('catalog/product')->load(8); $buyInfo = array( 'qty' => 1, // custom option id => value id // or // configurable attribute id => value id ); $quote->addProduct($product, new Varien_Object($buyInfo)); $addressData = array( 'firstname' => 'Test', 'lastname' => 'Test', 'street' => 'Sample Street 10', 'city' => 'Somewhere', 'postcode' => '123456', 'telephone' => '123456', 'country_id' => 'US', 'region_id' => 12, // id from directory_country_region table ); $billingAddress = $quote->getBillingAddress()->addData($addressData); $shippingAddress = $quote->getShippingAddress()->addData($addressData); $shippingAddress->setCollectShippingRates(true)->collectShippingRates() ->setShippingMethod('flatrate_flatrate') ->setPaymentMethod('checkmo'); $quote->getPayment()->importData(array('method' => 'checkmo')); $quote->collectTotals()->save(); $service = Mage::getModel('sales/service_quote', $quote); $service->submitAll(); $order = $service->getOrder(); printf("Created order %s\n", $order->getIncrementId()); ``` -
molotovbliss revised this gist
Jun 7, 2012 . 1 changed file with 28 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,6 +17,34 @@ Pear for 1.4, mage for 1.5. File downloaded into /downloader/.cache/community/ ./pear download magento-community/Shipping_Agent ./mage download community Shipping_Agent ## Download Archived extension manually without pear/mage ## If for some reason you need to download a Magento Connect extension archive from command line, use the following : wget http://connect.magentocommerce.com/TYPE/get/EXTENSION_NAME-X.X.X.tgz TYPE must be replaced with real extension type(usually core or community), EXTENSION_NAME with real(machine readable) extension name and X.X.X must be replaced with the real version number. To retrieve real TYPE and the real machine readable EXTENSION_NAME simply look at it’s extension key and take into a count it’s format magento-TYPE/EXTENSION_NAME. For example: http://www.magentocommerce.com/extension/518/blank-theme Extension key: magento-core/Interface_Frontend_Default_Blank Version(at the time of writing): 1.4.1.1 Download URL: wget http://connect.magentocommerce.com/core/get/Interface_Frontend_Default_Blank-1.4.1.1.tgz Other example: http://www.magentocommerce.com/extension/974/yoast-blank-seo-theme Extension key: magento-community/Yoast_Blank_Seo_Theme Version(at the time of writing): 1.4.1 Download URL: wget http://connect.magentocommerce.com/community/get/Yoast_Blank_Seo_Theme-1.4.1.tgz ## Clear cache/reindex ## ```php -
molotovbliss revised this gist
Jun 5, 2012 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,15 @@ # Magento Snippets # ## Export database with mysqldump minus log tables ## Example: (with tables to ignore from Magento minus usual stuff like -u -p etc.) ```sql mysqldump --ignore-table=db.log_customer -–ignore-table=db.log_quote -–ignore=db.log_summary –-ignore=db.log_summary_type –-ignore=db.log_url -–ignore=db.log_url_info -–ignore=db.log_visitor -–ignore=db.log_visitor_info --ignore=db.log_visitor_online –-ignore=db.log_summary –-ignore=db.enterprise_logging_event –-ignore=db.enterprise_logging_event_changes ``` Notes: - replace db. with your databasename and remove enterprise tables if community edition. - http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_ignore-table ## Download extension manually using pear/mage ## Pear for 1.4, mage for 1.5. File downloaded into /downloader/.cache/community/ -
molotovbliss revised this gist
Jun 5, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_ignore-ta Example: (with tables to ignore from Magento minus usual stuff like -u -p etc.) ```sql mysqldump --ignore-table=db.log_customer -–ignore-table=db.log_quote -–ignore=db.log_summary –-ignore=db.log_summary_type –-ignore=db.log_url -–ignore=db.log_url_info -–ignore=db.log_visitor -–ignore=db.log_visitor_info --ignore=db.log_visitor_online –-ignore=db.log_summary –-ignore=db.enterprise_logging_event –-ignore=db.enterprise_logging_event_changes ``` replace db. with your databasename and remove enterprise tables if community edition. -
molotovbliss revised this gist
Jun 5, 2012 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,16 @@ # Magento Snippets # ## Export database with mysqldump minus log tables ## http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_ignore-table Example: (with tables to ignore from Magento minus usual stuff like -u -p etc.) ```sql mysqldump –ignore-table=db.log_customer –ignore-table=db.log_quote –ignore=db.log_summary –ignore=db.log_summary_type –ignore=db.log_url –ignore=db.log_url_info –ignore=db.log_visitor –ignore=db.log_visitor_info –ignore=db.log_visitor_online –ignore=db.log_summary –ignore=db.enterprise_logging_event –ignore=db.enterprise_logging_event_changes ``` replace db. with your databasename and remove enterprise tables if community edition. ## Download extension manually using pear/mage ## Pear for 1.4, mage for 1.5. File downloaded into /downloader/.cache/community/ -
molotovbliss revised this gist
May 11, 2012 . 1 changed file with 39 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -616,4 +616,43 @@ if($routeName == 'cms' && $identifier == 'home') { } else { echo 'You are NOT in Homepage!'; } ``` ## Delete ALL Customers ## ``` sql SET FOREIGN_KEY_CHECKS=0; -- reset customers TRUNCATE customer_address_entity; TRUNCATE customer_address_entity_datetime; TRUNCATE customer_address_entity_decimal; TRUNCATE customer_address_entity_int; TRUNCATE customer_address_entity_text; TRUNCATE customer_address_entity_varchar; TRUNCATE customer_entity; TRUNCATE customer_entity_datetime; TRUNCATE customer_entity_decimal; TRUNCATE customer_entity_int; TRUNCATE customer_entity_text; TRUNCATE customer_entity_varchar; TRUNCATE log_customer; TRUNCATE log_visitor; TRUNCATE log_visitor_info; ALTER TABLE customer_address_entity AUTO_INCREMENT=1; ALTER TABLE customer_address_entity_datetime AUTO_INCREMENT=1; ALTER TABLE customer_address_entity_decimal AUTO_INCREMENT=1; ALTER TABLE customer_address_entity_int AUTO_INCREMENT=1; ALTER TABLE customer_address_entity_text AUTO_INCREMENT=1; ALTER TABLE customer_address_entity_varchar AUTO_INCREMENT=1; ALTER TABLE customer_entity AUTO_INCREMENT=1; ALTER TABLE customer_entity_datetime AUTO_INCREMENT=1; ALTER TABLE customer_entity_decimal AUTO_INCREMENT=1; ALTER TABLE customer_entity_int AUTO_INCREMENT=1; ALTER TABLE customer_entity_text AUTO_INCREMENT=1; ALTER TABLE customer_entity_varchar AUTO_INCREMENT=1; ALTER TABLE log_customer AUTO_INCREMENT=1; ALTER TABLE log_visitor AUTO_INCREMENT=1; ALTER TABLE log_visitor_info AUTO_INCREMENT=1; SET FOREIGN_KEY_CHECKS=1; ``` -
claudiu-marginean revised this gist
May 5, 2012 . No changes.There are no files selected for viewing
-
claudiu-marginean revised this gist
May 5, 2012 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ <block type="cms/block" name="block_name"> <action method="setBlockId"><id>block_code</id></action> </block> {{block type="cms/block" block_id="block_code"}} {{block type="catalog/product_list" category_id="79" template="catalog/product/list_random.phtml"}}
NewerOlder