snipt

Ctrl+h for KB shortcuts

PHP

Call CMS Block in PHTML Page

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('cmsblocknamehere')->toHtml() ?>
https://snipt.net/embed/dc16edbb8df24e294fe88376136c1d9b/
/raw/dc16edbb8df24e294fe88376136c1d9b/
dc16edbb8df24e294fe88376136c1d9b
php
PHP
1
2019-07-10T15:27:43
True
False
False
/api/public/snipt/16979/
call-cms-block-in-phtml-page
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">getLayout</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">createBlock</span><span class="p">(</span><span class="s1">&#39;cms/block&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">setBlockId</span><span class="p">(</span><span class="s1">&#39;cmsblocknamehere&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">toHtml</span><span class="p">()</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
magento

PHP

Get Customer Group ID #

<?php $grpNum = Mage::getSingleton('customer/session')->getCustomerGroupId(); ?>
https://snipt.net/embed/3cadf5805871be496c12e9aaf342f0dc/
/raw/3cadf5805871be496c12e9aaf342f0dc/
3cadf5805871be496c12e9aaf342f0dc
php
PHP
2
2019-08-07T21:54:20
True
False
False
/api/public/snipt/16794/
get-customer-group-id
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> <span class="nv">$grpNum</span> <span class="o">=</span> <span class="nx">Mage</span><span class="o">::</span><span class="na">getSingleton</span><span class="p">(</span><span class="s1">&#39;customer/session&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">getCustomerGroupId</span><span class="p">();</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
magento

PHP

Display product discription on cart page

<?php $custom = Mage::getModel('catalog/product')->load($_item->getProductId());?>
<?php echo $custom->getShortDescription(); ?>
https://snipt.net/embed/2c541cb1c5ec9e16e3290a2d92588635/
/raw/2c541cb1c5ec9e16e3290a2d92588635/
2c541cb1c5ec9e16e3290a2d92588635
php
PHP
3
2019-08-18T07:11:18
True
False
False
/api/public/snipt/16562/
display-product-discription-on-cart-page
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> <span class="nv">$custom</span> <span class="o">=</span> <span class="nx">Mage</span><span class="o">::</span><span class="na">getModel</span><span class="p">(</span><span class="s1">&#39;catalog/product&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">load</span><span class="p">(</span><span class="nv">$_item</span><span class="o">-&gt;</span><span class="na">getProductId</span><span class="p">());</span><span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-2"><a name="L-2"></a><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$custom</span><span class="o">-&gt;</span><span class="na">getShortDescription</span><span class="p">();</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
magento

PHP

Skin url for images

1
2
3
<?php $this->getSkinUrl('images/image.jpg') ?>
or
<?php echo($this->getSkinUrl('images/findoutmoresmall.png')) ?>
https://snipt.net/embed/684f81ee44fea9a40c73d29d09c816e4/
/raw/684f81ee44fea9a40c73d29d09c816e4/
684f81ee44fea9a40c73d29d09c816e4
php
PHP
3
2019-07-10T08:28:11
True
False
False
/api/public/snipt/16451/
skin-url-for-images
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">getSkinUrl</span><span class="p">(</span><span class="s1">&#39;images/image.jpg&#39;</span><span class="p">)</span> <span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-2"><a name="L-2"></a><span class="x">or</span> </span><span id="L-3"><a name="L-3"></a><span class="cp">&lt;?php</span> <span class="k">echo</span><span class="p">(</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">getSkinUrl</span><span class="p">(</span><span class="s1">&#39;images/findoutmoresmall.png&#39;</span><span class="p">))</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
magento

PHP

Display homepage only

1
2
3
4
5
<?php if (Mage::helper('core/url')->getCurrentUrl() === Mage::helper('core/url')->getHomeUrl()):?>
// For some reason this conflicts with Magento cache in 1.4.1.1 - Suggested use the one below:


<?php if (Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms' && Mage::getSingleton('cms/page')->getIdentifier() == 'home') : ?>
https://snipt.net/embed/19c59aa4152020a997596cf21522217f/
/raw/19c59aa4152020a997596cf21522217f/
19c59aa4152020a997596cf21522217f
php
PHP
5
2019-08-01T00:29:42
True
False
False
/api/public/snipt/16448/
display-homepage-only
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> <span class="k">if</span> <span class="p">(</span><span class="nx">Mage</span><span class="o">::</span><span class="na">helper</span><span class="p">(</span><span class="s1">&#39;core/url&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">getCurrentUrl</span><span class="p">()</span> <span class="o">===</span> <span class="nx">Mage</span><span class="o">::</span><span class="na">helper</span><span class="p">(</span><span class="s1">&#39;core/url&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">getHomeUrl</span><span class="p">())</span><span class="o">:</span><span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-2"><a name="L-2"></a><span class="x">// For some reason this conflicts with Magento cache in 1.4.1.1 - Suggested use the one below:</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="cp">&lt;?php</span> <span class="k">if</span> <span class="p">(</span><span class="nx">Mage</span><span class="o">::</span><span class="na">app</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">getFrontController</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">getRequest</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">getRouteName</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;cms&#39;</span> <span class="o">&amp;&amp;</span> <span class="nx">Mage</span><span class="o">::</span><span class="na">getSingleton</span><span class="p">(</span><span class="s1">&#39;cms/page&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">getIdentifier</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;home&#39;</span><span class="p">)</span> <span class="o">:</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
magento

PHP

Magento: debug

1
2
3
4
5
<?php 

// debug in magento

Zend_Debug::dump($_product->getData()); 
https://snipt.net/embed/33703ae8e5780b2f4d873fae5589eabd/
/raw/33703ae8e5780b2f4d873fae5589eabd/
33703ae8e5780b2f4d873fae5589eabd
php
PHP
5
2019-08-18T11:32:44
True
False
False
/api/public/snipt/16413/
magento-debug
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="c1">// debug in magento</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="nx">Zend_Debug</span><span class="o">::</span><span class="na">dump</span><span class="p">(</span><span class="nv">$_product</span><span class="o">-&gt;</span><span class="na">getData</span><span class="p">());</span> </span></pre></div> </td></tr></table>
debug, magento