-
-
Save natrod/3034c204745b1610a19d to your computer and use it in GitHub Desktop.
Revisions
-
klein0r revised this gist
Jan 27, 2014 . 1 changed file with 14 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 @@ -718,3 +718,17 @@ $localeCode = Mage::getStoreConfig('general/locale/code', $storeId); ?> ``` ```xml <frontend> <product> <collection> <attributes> <globalname/> <merkmal_228/> </attributes> </collection> </product> </frontend> ``` -
klein0r revised this gist
Jan 15, 2014 . 1 changed file with 1 addition 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 @@ -7,6 +7,7 @@ - Direct download Magento extensions: http://freegento.com/ddl-magento-extension.php - Delete all orders from database: http://www.codelogbook.com/remove-all-orders-from-magento-database/ - Magereverse http://www.magereverse.com/ ## Download extension manually using pear/mage ## -
klein0r revised this gist
Dec 3, 2013 . 1 changed file with 2 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 @@ -713,5 +713,7 @@ require_once Mage::getModuleDir('controllers', 'Mage_Checkout') . DS . 'CartCont Mage::helper('core')->currency($field, true, false); $localeCode = Mage::getStoreConfig('general/locale/code', $storeId); ?> ``` -
klein0r revised this gist
Nov 6, 2013 . 1 changed file with 1 addition 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 @@ -6,6 +6,7 @@ ### Helpful Urls ### - Direct download Magento extensions: http://freegento.com/ddl-magento-extension.php - Delete all orders from database: http://www.codelogbook.com/remove-all-orders-from-magento-database/ ## Download extension manually using pear/mage ## -
klein0r revised this gist
Oct 23, 2013 . 1 changed file with 3 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 @@ -709,5 +709,8 @@ Mage::app()->getStore()->isAdmin() ```php <?php require_once Mage::getModuleDir('controllers', 'Mage_Checkout') . DS . 'CartController.php'; Mage::helper('core')->currency($field, true, false); ?> ``` -
klein0r revised this gist
Oct 4, 2013 . 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 @@ -705,3 +705,9 @@ Mage::app()->getStore()->isAdmin() ``` {{block type="core/template" template="cms/startseite.phtml"}} ``` ```php <?php require_once Mage::getModuleDir('controllers', 'Mage_Checkout') . DS . 'CartController.php'; ?> ``` -
klein0r revised this gist
Sep 2, 2013 . 1 changed file with 7 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 @@ -698,4 +698,10 @@ $installer->endSetup(); $templateName = Mage::getDesign()->getTemplateFilename('path/to/template', $params); Mage::app()->getStore()->isAdmin() ?> ``` ## Unsorted ## ``` {{block type="core/template" template="cms/startseite.phtml"}} ``` -
klein0r revised this gist
Aug 22, 2013 . 1 changed file with 12 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 @@ -459,6 +459,18 @@ Mage::getConfig()->getModuleConfig('Sitewards_B2BProfessional')->is('active', 't ?> ``` ### Read and write configuration values ```php <?php // Read data $mailTemplateId = Mage::getStoreConfig('YOUR/PATH/HERE', $storeId); // Write data Mage::getModel('core/config')->saveConfig('YOUR/PATH/HERE', $value ); ?> ``` ## Update all subscribers into a customer group (e.g. 5) ## ```sql -
klein0r revised this gist
Aug 19, 2013 . 1 changed file with 3 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 @@ -269,10 +269,11 @@ to `page.xml`, and then add the `mytemplate.phtml` file. Any block added to the <?php Mage::log('Your Log Message', Zend_Log::INFO, 'your_log_file.log'); ?> ``` ### Send success / errors to session ### ```php <?php Mage::getSingleton('core/session')->addSuccess($this->__('Hello world.')); ?> <?php Mage::getSingleton('core/session')->addError($this->__('Bad world!!')); ?> ``` ## Configuration ## -
klein0r revised this gist
Jul 30, 2013 . No changes.There are no files selected for viewing
-
klein0r revised this gist
Jun 26, 2013 . 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 @@ -355,7 +355,7 @@ Make sure the block that you’re working is of the type catalog/navigation. If ## Environment and Debugging ## ### Helpful Debug watches ### ```php <?php -
klein0r revised this gist
Jun 26, 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 @@ -355,6 +355,14 @@ Make sure the block that you’re working is of the type catalog/navigation. If ## Environment and Debugging ## ## Helpful Debug watches ## ```php <?php file_put_contents(sprintf('/tmp/layout_%s.xml', $this->getAction()->getFullActionName()), $this->getLayout()->getXmlString()) ?> ``` ### Debug using zend ### ```php -
klein0r revised this gist
Jun 8, 2013 . 1 changed file with 285 additions and 223 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,17 +1,31 @@ # Magento Tips, Tricks and Snippets # ## Extensions ## ### Helpful Urls ### - Direct download Magento extensions: http://freegento.com/ddl-magento-extension.php ## 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 ``` ## Caching ## ### Clear cache/reindex ### ```php <?php // clear cache Mage::app()->removeCache('catalog_rules_dirty'); // reindex prices Mage::getModel('index/process')->load(2)->reindexEverything(); /* @@ -26,11 +40,15 @@ Mage::getModel('index/process')->load(2)->reindexEverything(); 9 = Stock Status */ // Recreate a single index programmatically Mage::getModel('index/process')->load(Mage_Catalog_Helper_Product_Flat::CATALOG_FLAT_PROCESS_CODE, 'indexer_code')->reindexEverything(); ?> ``` ## Categories and Products ## ### Load category by id ### ```php <?php @@ -39,7 +57,7 @@ $_category_url = $_category->getUrl(); ?> ``` ### Load product by id or sku ### ```php <?php @@ -49,7 +67,7 @@ $_product_2 = Mage::getModel('catalog/product')->loadByAttribute('sku','cordoba- ``` ### Get Configurable product's Child products ### ```php <?php @@ -58,7 +76,7 @@ $childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedPro ?> ``` ### Get Configurable product's Children's (simple product) custom attributes ### ```php <?php @@ -71,19 +89,143 @@ foreach($col as $simple_product){ ?> ``` ### Is product purchasable? ### ```php <?php if($_product->isSaleable()) { // do stuff } ?> ``` ### Load Products by Category ID ### ```php <?php $_category = Mage::getModel('catalog/category')->load(47); $_productCollection = $_category->getProductCollection(); if($_productCollection->count()) { foreach( $_productCollection as $_product ): echo $_product->getProductUrl(); echo $this->getPriceHtml($_product, true); echo $this->htmlEscape($_product->getName()); endforeach; } ?> ``` ### Get The Root Category ### ```php <?php $rootCategoryId = Mage::app()->getStore()->getRootCategoryId(); $_category = Mage::getModel('catalog/category')->load($rootCategoryId); // You can then get all of the top level categories using: $_subcategories = $_category->getChildrenCategories(); ?> ``` ### Return Product Attributes ### ```php <?php $_product->getThisattribute(); $_product->getAttributeText('thisattribute'); $_product->getResource()->getAttribute('thisattribute')->getFrontend()->getValue($_product); $_product->getData('thisattribute'); // The following returns the option IDs for an attribute that is a multiple-select field: $_product->getData('color'); // i.e. 456,499 // The following returns the attribute object, and instance of Mage_Catalog_Model_Resource_Eav_Attribute: $_product->getResource()->getAttribute('color'); // instance of Mage_Catalog_Model_Resource_Eav_Attribute // The following returns an array of the text values for the attribute: $_product->getAttributeText('color') // Array([0]=>'red', [1]=>'green') // The following returns the text for the attribute if ($attr = $_product->getResource()->getAttribute('color')): echo $attr->getFrontend()->getValue($_product); // will display: red, green endif; ?> ``` ### Get Simple Products of a Configurable Product ### ```php <?php if($_product->getTypeId() == "configurable") { $ids = $_product->getTypeInstance()->getUsedProductIds(); ?> <ul> <?php foreach ($ids as $id) { $simpleproduct = Mage::getModel('catalog/product')->load($id); ?> <li> <?php echo $simpleproduct->getName() . " - " . (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($simpleproduct)->getQty(); ?> </li> <?php } ?> </ul> <?php } ?> ``` ### Getting Configurable Product from Simple Product ID in Magento 1.5+ ### ```php <?php $simpleProductId = 465; $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable') ->getParentIdsByChild($simpleProductId); $product = Mage::getModel('catalog/product')->load($parentIds[0]); echo $product->getId(); // ID = 462 (aka, Parent of 465) # Generate URL to variant of configurable by $sku $simple = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku); $productId = array_shift(Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($simple->getId())); $url = Mage::getUrl('catalog/product/view', array( 'id' => $productId, 'option_id' => $simple->getVariant() )); ?> ``` ### Get the current category/product/cms page ### ```php <?php $currentCategory = Mage::registry('current_category'); $currentProduct = Mage::registry('current_product'); $currentCmsPage = Mage::registry('cms_page'); ?> ``` ### Get associated products ### In /app/design/frontend/default/site/template/catalog/product/view/type/ ``` php <?php $_helper = $this->helper('catalog/output'); ?> <?php $_associatedProducts = $this->getAllowProducts() ?> <?php //var_dump($_associatedProducts); ?> <br /> <br /> <?php if (count($_associatedProducts)): ?> <?php foreach ($_associatedProducts as $_item): ?> <a href="<?php echo $_item->getProductUrl() ?>"><?php echo $_helper->productAttribute($_item, $_item->getName(), 'name') ?> | <?php echo $_item->getName() ?> | <?php echo $_item->getPrice() ?></a> <br /> <br /> <?php endforeach; ?> <?php endif; ?> ``` ## Blocks ## ### Call Static Block ### ```php <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('block-name')->toHtml(); ?> ``` ### Add JavaScript to page ### First approach: page.xml - you can add something like @@ -103,46 +245,39 @@ Normally, the getChildHtml method is used to render a specific child block. Howe ```xml <!-- existing line --> <block type="page/html_head" name="head" as="head"> <!-- new sub-block you're adding --> <block type="core/template" name="mytemplate" as="mytemplate" template="page/mytemplate.phtml"/> ... ``` 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). ## Customer handling ## ### Check if customer is logged in ### ```php <?php $logged_in = Mage::getSingleton('customer/session')->isLoggedIn(); // (boolean) ?> ``` ## Logging and Exception handling ## ### Log to custom file ### ```php <?php Mage::log('Your Log Message', Zend_Log::INFO, 'your_log_file.log'); ?> ``` ### Send errors to session ### ```php <?php Mage::getSingleton('core/session')->addError('Any exception text'); ?> ``` ## Configuration ## ### Programmatically change or read Magento’s core config data ### ```php <?php @@ -157,7 +292,7 @@ $my_change_config->saveConfig('design/head/demonotice', "0", 'default', 0); ?> ``` ### Changing the Admin URL ### Open up the `/app/etc/local.xml` file, locate the `<frontName>` tag, and change the ‘admin’ part it to something a lot more random, eg: @@ -167,6 +302,11 @@ Open up the `/app/etc/local.xml` file, locate the `<frontName>` tag, and change Clear your cache and sessions. ## Magento: Mass Exclude/Unexclude Images ## 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. @@ -178,39 +318,6 @@ UPDATE`catalog_product_entity_media_gallery_value` SET `disabled` = '0' WHERE `d UPDATE`catalog_product_entity_media_gallery_value` SET `disabled` = '1' WHERE `disabled` = '0'; ``` ## Category Navigation Listings in Magento ## @@ -246,27 +353,75 @@ Make sure the block that you’re working is of the type catalog/navigation. If </div> ``` ## Environment and Debugging ## ### Debug using zend ### ```php <?php echo Zend_Debug::dump($thing_to_debug, 'debug'); ?> ``` ### Run Magento Code Externally ### ```php <?php require_once('app/Mage.php'); //Path to Magento umask(0); Mage::app(); // Run you code here ?> ``` ### Turn template hints on/off via database ### ```sql UPDATE `core_config_data` SET `value` = 0 WHERE `path` = "dev/debug/template_hints" OR `path` = "dev/debug/template_hints_blocks"; ``` ### Delete all products ### ```sql 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_decimal`; TRUNCATE TABLE `catalog_product_link_attribute_int`; TRUNCATE TABLE `catalog_product_link_attribute_varchar`; 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`; 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_item`; TRUNCATE TABLE `cataloginventory_stock_status`; ``` ### Get methods of an object ### First, use `get_class` to get the name of an object's class. @@ -287,25 +442,11 @@ foreach($methods as $method) ?> ``` ### Check if module is installed/active ### ```php <?php Mage::getConfig()->getModuleConfig('Sitewards_B2BProfessional')->is('active', 'true'); ?> ``` @@ -323,25 +464,6 @@ AND newsletter_subscriber.`subscriber_status` = 1; ``` ## Get An Array of Country Names/Codes in Magento ## ```php @@ -387,27 +509,6 @@ $_countries = Mage::getResourceModel('directory/country_collection') ?> ``` ## Cart Data ## ```php @@ -424,101 +525,23 @@ foreach ($session->getQuote()->getAllItems() as $item) { ?> ``` ## URLs, Requests and Responses ## ### $_GET, $_POST & $_REQUEST Variables ### ```php <?php // $_GET $productId = Mage::app()->getRequest()->getParam('product_id'); // The second parameter to getParam allows you to set a default value which is returned if the GET value isn't set $productId = Mage::app()->getRequest()->getParam('product_id', 44); $postData = Mage::app()->getRequest()->getPost(); // You can access individual variables like... $productId = $postData['product_id']); ?> ``` ### Redirecting to other location ### ```php @@ -549,20 +572,47 @@ if ($request->isXmlHttpRequest()) { echo 'yes'; } ?> ``` ### Get The Current URL In Magento ### ```php <?php echo Mage::helper('core/url')->getCurrentUrl(); ?> ``` ### getBaseUrl – Magento URL Path ### ```php <?php // http://example.com/ echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); // http://example.com/js/ echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS); // http://example.com/index.php/ echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK); // http://example.com/media/ echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); // http://example.com/skin/ echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN); ?> ``` ### Customer login url with redirect to current page ### ```php <?php Mage::getUrl('customer/account/login', array ( Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME => Mage::helper('core')->urlEncode(Mage::getUrl('*/*/*', array('_current' => true))) )); ?>'); ?> ``` ## Setups ## ### File names ### - mysql4-install-0.1.0.php - mysql4-upgrade-0.1.0-0.1.1.php ### Config XML Layout ### ``` <global> <resources> @@ -588,6 +638,8 @@ Mage::getUrl('customer/account/login', array ( Mage_Customer_Helper_Data::REFERE </global> ``` ### Attribute creation ### ```php <?php $installer = $this; @@ -615,4 +667,14 @@ Mage::getSingleton('eav/config') $installer->endSetup(); ?> ``` ## Other Helpful stuff ## ```php <?php $templateName = Mage::getDesign()->getTemplateFilename('path/to/template', $params); Mage::app()->getStore()->isAdmin() ?> ``` -
klein0r revised this gist
Jun 7, 2013 . 1 changed file with 59 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 @@ -556,4 +556,63 @@ Mage::getConfig()->getModuleConfig('Sitewards_B2BProfessional')->is('active', 't Mage::app()->getStore()->isAdmin() Mage::getUrl('customer/account/login', array ( Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME => Mage::helper('core')->urlEncode(Mage::getUrl('*/*/*', array('_current' => true))) )); ?>'); ?> ``` ## Setups ## - mysql4-install-0.1.0.php - mysql4-upgrade-0.1.0-0.1.1.php ``` <global> <resources> <modulename_setup> <setup> <module>MKleine_Modulename</module> </setup> <connection> <use>core_setup</use> </connection> </modulename_setup> <modulename_write> <connection> <use>core_write</use> </connection> </modulename_write> <modulename_read> <connection> <use>core_read</use> </connection> </modulename_read> </resources> </global> ``` ```php <?php $installer = $this; $setup = new Mage_Eav_Model_Entity_Setup('core_setup'); $installer->startSetup(); $setup->addAttribute('customer', 'attribute_name', array( 'label' => 'Händlersuche erlaubt', 'type' => 'int', 'input' => 'select', 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 'source' => 'eav/entity_attribute_source_boolean', 'default' => 0, 'visible' => true, 'required' => false, 'user_defined' => true, 'is_user_defined' => true, 'position' => 100, )); Mage::getSingleton('eav/config') ->getAttribute('customer', 'attribute_name') ->setData('used_in_forms', array('adminhtml_customer')) ->save(); $installer->endSetup(); ?> ``` -
klein0r revised this gist
May 24, 2013 . 1 changed file with 6 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 @@ -549,6 +549,11 @@ if ($request->isXmlHttpRequest()) { echo 'yes'; } ?> ``` ```php <?php $templateName = Mage::getDesign()->getTemplateFilename('path/to/template', $params); Mage::getConfig()->getModuleConfig('Sitewards_B2BProfessional')->is('active', 'true'); Mage::app()->getStore()->isAdmin() Mage::getUrl('customer/account/login', array ( Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME => Mage::helper('core')->urlEncode(Mage::getUrl('*/*/*', array('_current' => true))) )); ?>'); ?> ``` -
klein0r revised this gist
May 18, 2013 . 1 changed file with 3 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 @@ -549,5 +549,6 @@ if ($request->isXmlHttpRequest()) { echo 'yes'; } ?> ``` $templateName = Mage::getDesign()->getTemplateFilename('path/to/template', $params); Mage::getConfig()->getModuleConfig('Sitewards_B2BProfessional')->is('active', 'true'); Mage::app()->getStore()->isAdmin() -
klein0r revised this gist
May 17, 2013 . 1 changed file with 2 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 @@ -549,4 +549,5 @@ if ($request->isXmlHttpRequest()) { echo 'yes'; } ?> ``` $templateName = Mage::getDesign()->getTemplateFilename($this->getTemplate(), $params); Mage::getConfig()->getModuleConfig('Sitewards_B2BProfessional')->is('active', 'true') -
klein0r revised this gist
May 16, 2013 . 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 @@ -547,4 +547,6 @@ $param = $controller->getRequest()->getPost('myPostParameterName'); if ($request->isXmlHttpRequest()) { echo 'yes'; } ?> ``` $templateName = Mage::getDesign()->getTemplateFilename($this->getTemplate(), $params); -
klein0r revised this gist
Apr 26, 2013 . 1 changed file with 2 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 @@ -25,6 +25,8 @@ Mage::getModel('index/process')->load(2)->reindexEverything(); 8 = Tag Aggregation Data 9 = Stock Status */ Mage::getModel('index/process')->load(Mage_Catalog_Helper_Product_Flat::CATALOG_FLAT_PROCESS_CODE, 'indexer_code')->reindexEverything(); ?> ``` -
klein0r revised this gist
Apr 23, 2013 . 1 changed file with 39 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 @@ -113,6 +113,12 @@ to `page.xml`, and then add the `mytemplate.phtml` file. Any block added to the <?php $logged_in = Mage::getSingleton('customer/session')->isLoggedIn(); // (boolean) ?> ``` ## Send errors ## ```php <?php Mage::getSingleton('core/session')->addError('Any exception text'); ?> ``` ## Get the current category/product/cms page ## ```php @@ -134,7 +140,7 @@ Mage::app(); ?> ``` ## Programmatically change or read Magento’s core config data ## ```php <?php @@ -144,6 +150,8 @@ $my_change_config = new Mage_Core_Model_Config(); $my_change_config->saveConfig('design/head/demonotice', "1", 'default', 0); // turns notice off $my_change_config->saveConfig('design/head/demonotice', "0", 'default', 0); ?> ``` @@ -498,15 +506,43 @@ $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable') ->getParentIdsByChild($simpleProductId); $product = Mage::getModel('catalog/product')->load($parentIds[0]); echo $product->getId(); // ID = 462 (aka, Parent of 465) # Generate URL to variant of configurable by $sku $simple = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku); $productId = array_shift(Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($simple->getId())); $url = Mage::getUrl('catalog/product/view', array( 'id' => $productId, 'option_id' => $simple->getVariant() )); ?> ``` ## URLs, Requests and Responses ## ### Redirecting to other location ### ```php <?php $target = 'http://klein0r.de'; Mage::app()->getFrontController()->getResponse()->setRedirect($target)->sendResponse(); exit; ?> ``` ### Parameters ### ```php <?php $request = Mage::app()->getRequest(); $response = Mage::app()->getResponse(); # All pameters by controller $controller = Mage::registry('controller'); $params = $controller->getRequest()->getParams(); # Get a specific post parameter $param = $controller->getRequest()->getPost('myPostParameterName'); # Check Ajax-Requests if ($request->isXmlHttpRequest()) { echo 'yes'; } ?> ``` -
klein0r revised this gist
Apr 23, 2013 . 1 changed file with 2 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 @@ -504,7 +504,9 @@ echo $product->getId(); // ID = 462 (aka, Parent of 465) ## Redirecting to other location ## ```php <?php $target = 'http://www.traumschwinger.at'; Mage::app()->getFrontController()->getResponse()->setRedirect($target)->sendResponse(); exit; ?> ``` -
klein0r revised this gist
Apr 23, 2013 . 1 changed file with 9 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,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) ?> ``` ## Redirecting to other location ## ```php $target = 'http://www.traumschwinger.at'; Mage::app()->getFrontController()->getResponse()->setRedirect($target)->sendResponse(); exit; ``` -
davidalexander revised this gist
Oct 18, 2011 . 1 changed file with 12 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 @@ -487,4 +487,16 @@ TRUNCATE TABLE `catalog_product_website`; TRUNCATE TABLE `catalog_product_entity`; TRUNCATE TABLE `cataloginventory_stock_item`; TRUNCATE TABLE `cataloginventory_stock_status`; ``` ## Getting Configurable Product from Simple Product ID in Magento 1.5+ ## ```php <?php $simpleProductId = 465; $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable') ->getParentIdsByChild($simpleProductId); $product = Mage::getModel('catalog/product')->load($parentIds[0]); echo $product->getId(); // ID = 462 (aka, Parent of 465) ?> ``` -
davidalexander revised this gist
Sep 8, 2011 . 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 @@ -455,7 +455,7 @@ OR ## Delete all products ## ```sql TRUNCATE TABLE `catalog_product_bundle_option`; TRUNCATE TABLE `catalog_product_bundle_option_value`; TRUNCATE TABLE `catalog_product_bundle_selection`; -
davidalexander revised this gist
Sep 8, 2011 . 1 changed file with 36 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 @@ -440,7 +440,6 @@ if($_product->getTypeId() == "configurable") { ?> ``` ## Turn template hints on/off via database ## ```sql @@ -452,4 +451,40 @@ WHERE `path` = "dev/debug/template_hints" OR `path` = "dev/debug/template_hints_blocks"; ``` ## Delete all products ## ``sql 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_decimal`; TRUNCATE TABLE `catalog_product_link_attribute_int`; TRUNCATE TABLE `catalog_product_link_attribute_varchar`; 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`; 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_item`; TRUNCATE TABLE `cataloginventory_stock_status`; ``` -
davidalexander revised this gist
Aug 18, 2011 . 1 changed file with 14 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 @@ -438,4 +438,18 @@ if($_product->getTypeId() == "configurable") { <?php } ?> ``` ## Turn template hints on/off via database ## ```sql UPDATE `core_config_data` SET `value` = 0 WHERE `path` = "dev/debug/template_hints" OR `path` = "dev/debug/template_hints_blocks"; ``` -
davidalexander revised this gist
Jul 31, 2011 . 1 changed file with 26 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 @@ -412,4 +412,30 @@ foreach ($session->getQuote()->getAllItems() as $item) { Zend_Debug::dump($item->debug()); } ?> ``` ## Get Simple Products of a Configurable Product ## ```php <?php if($_product->getTypeId() == "configurable") { $ids = $_product->getTypeInstance()->getUsedProductIds(); ?> <ul> <?php foreach ($ids as $id) { $simpleproduct = Mage::getModel('catalog/product')->load($id); ?> <li> <?php echo $simpleproduct->getName() . " - " . (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($simpleproduct)->getQty(); ?> </li> <?php } ?> </ul> <?php } ?> ``` -
davidalexander revised this gist
Jul 19, 2011 . 1 changed file with 16 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 @@ -396,4 +396,20 @@ if ($attr = $_product->getResource()->getAttribute('color')): echo $attr->getFrontend()->getValue($_product); // will display: red, green endif; ?> ``` ## Cart Data ## ```php <?php $cart = Mage::getModel('checkout/cart')->getQuote()->getData(); print_r($cart); $cart = Mage::helper('checkout/cart')->getCart()->getItemsCount(); print_r($cart); $session = Mage::getSingleton('checkout/session'); foreach ($session->getQuote()->getAllItems() as $item) { echo $item->getName(); Zend_Debug::dump($item->debug()); } ?> ``` -
davidalexander revised this gist
Jul 19, 2011 . 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 @@ -385,5 +385,15 @@ $_product->getThisattribute(); $_product->getAttributeText('thisattribute'); $_product->getResource()->getAttribute('thisattribute')->getFrontend()->getValue($_product); $_product->getData('thisattribute'); // The following returns the option IDs for an attribute that is a multiple-select field: $_product->getData('color'); // i.e. 456,499 // The following returns the attribute object, and instance of Mage_Catalog_Model_Resource_Eav_Attribute: $_product->getResource()->getAttribute('color'); // instance of Mage_Catalog_Model_Resource_Eav_Attribute // The following returns an array of the text values for the attribute: $_product->getAttributeText('color') // Array([0]=>'red', [1]=>'green') // The following returns the text for the attribute if ($attr = $_product->getResource()->getAttribute('color')): echo $attr->getFrontend()->getValue($_product); // will display: red, green endif; ?> ``` -
davidalexander revised this gist
Jul 17, 2011 . 1 changed file with 6 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 @@ -113,10 +113,14 @@ to `page.xml`, and then add the `mytemplate.phtml` file. Any block added to the <?php $logged_in = Mage::getSingleton('customer/session')->isLoggedIn(); // (boolean) ?> ``` ## Get the current category/product/cms page ## ```php <?php $currentCategory = Mage::registry('current_category'); $currentProduct = Mage::registry('current_product'); $currentCmsPage = Mage::registry('cms_page'); ?> ``` ## Run Magento Code Externally ##
NewerOlder