Skip to content

Instantly share code, notes, and snippets.

@ghanbak
Last active May 24, 2017 16:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghanbak/6942319 to your computer and use it in GitHub Desktop.
Save ghanbak/6942319 to your computer and use it in GitHub Desktop.
This gist is dedicated to handling all things related within the programming of Magento.

All Things Magento

Categories

GET ID

<?php  if($_product->getCategoryId() != 4) : ?>
<?php if($category->getId() != 23):?>
<?php echo Mage::getModel("catalog/category")->load(5)->getUrl() ?> 

Mobile Theming

Insert this into your design exception as a Magento Expression.

iPhone|iPod|BlackBerry|Palm|Googlebot-Mobile|Mobile|mobile|mobi|Windows Mobile|Safari Mobile|Android|Opera Mini

Product Count

<?php
  $_productCollection = clone $this->getLoadedProductCollection();
  $_productCollection ->clear()->setPageSize(3) // Number of product allowed on page->load();
  $_helper = $this->helper('catalog/output');
?>

Truncate

<?php echo Mage::helper('core/string')->truncate($post->getPostExcerpt(), '150'); ?>

Add Attributes

  • this should work for drop downs and multi-select
<?php echo $_product->getAttributeText('attribute_name'); ?>
  • this should work for text fields
<?php echo $_product->getAttributeName(); ?>
  • this should work for text areas
<?php echo $_helper->productAttribute($_product, nl2br($_product->getAttributeName()), 'attribute_name') ?>
  • this is another possible method
<?php echo $this->htmlEscape($_product->getData('attribute_name')); ?>

Add a CMS Block

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('your_block_id')->toHtml(); ?>

Installing Magento Modules

Magento Connect

Go to the extension page and click install. You will be prompted to either login or get the extension key. Depending on your choice here are the two syntax options.

Before moving forward, type chmod +x mage on the root of your magento site.

Connect 2.0

./mage install http://connect20.magentocommerce.com/community/ Extension_Name

Connect 1.0

./mage install community Extension_Name

Magento State

You can use these to install extensions that are in beta or stable.

./mage config-set preferred_state beta
./mage config-set preferred_state stable

Magento Copyright Date

This will print you're Copyright Field in Magento's Admin and still maintain a dynamic year. Add it to this file: design/frontend/yourTheme/yourTheme/template/page/html/footer.phtml

<?php echo preg_replace('/<YEAR\/>/', date("Y"), $this->getCopyright()) ?>

In Magento's Admin, you can place this in the Copyright field:

&copy; <YEAR/> All Rights Reserved

Ash Up and Ash Core

curl -sL https://s3.amazonaws.com/augustash/up | ruby

After install logout and log back in through Magento admin interface

Installing Ash Modules
php shell/up.php update
php shell/up.php --install ash_admin,ash_fontawesome,ash_jquery,ash_updater

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment