snipt

Ctrl+h for KB shortcuts

PHP

Echo customer name/firstname in Magento

1
2
3
4
5
6
7
<?php $session = Mage::getSingleton('customer/session');
if($session->isLoggedIn()) {
   $customer = $session->getCustomer();
   echo $customer->getName();
   echo $customer->getFirstname();
}
?>
https://snipt.net/embed/ef561dc714a1dc9d61022124d9131d3d/
/raw/ef561dc714a1dc9d61022124d9131d3d/
ef561dc714a1dc9d61022124d9131d3d
php
PHP
7
2019-06-06T20:53:05
True
False
False
/api/public/snipt/22256/
echo-customer-namefirstname-in-magento
<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> <a href="#L-6">6</a> <a href="#L-7">7</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">$session</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><span id="L-2"><a name="L-2"></a><span class="k">if</span><span class="p">(</span><span class="nv">$session</span><span class="o">-&gt;</span><span class="na">isLoggedIn</span><span class="p">())</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="nv">$customer</span> <span class="o">=</span> <span class="nv">$session</span><span class="o">-&gt;</span><span class="na">getCustomer</span><span class="p">();</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">echo</span> <span class="nv">$customer</span><span class="o">-&gt;</span><span class="na">getName</span><span class="p">();</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">echo</span> <span class="nv">$customer</span><span class="o">-&gt;</span><span class="na">getFirstname</span><span class="p">();</span> </span><span id="L-6"><a name="L-6"></a><span class="p">}</span> </span><span id="L-7"><a name="L-7"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
magento

PHP

Load static block

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('name_of_block')->toHtml() ?>
https://snipt.net/embed/ece28c8702ff5b54080a78d17cf673f5/
/raw/ece28c8702ff5b54080a78d17cf673f5/
ece28c8702ff5b54080a78d17cf673f5
php
PHP
1
2019-06-13T22:58:37
True
False
False
/api/public/snipt/22149/
load-static-block
<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;name_of_block&#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

Magento cart total

<?php echo $this->helper('checkout')->formatPrice(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal()); ?>
https://snipt.net/embed/96c9ec39fc420ec26f2f79be0a0a2f62/
/raw/96c9ec39fc420ec26f2f79be0a0a2f62/
96c9ec39fc420ec26f2f79be0a0a2f62
php
PHP
1
2019-06-07T12:30:23
True
False
False
/api/public/snipt/21968/
magento-cart-total
<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">helper</span><span class="p">(</span><span class="s1">&#39;checkout&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">formatPrice</span><span class="p">(</span><span class="nx">Mage</span><span class="o">::</span><span class="na">getSingleton</span><span class="p">(</span><span class="s1">&#39;checkout/cart&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">getQuote</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">getGrandTotal</span><span class="p">());</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
magento

PHP

Magento: display store id

1
2
3
4
<?php

// display store ID
echo "Store ID = " . Mage::app()->getStore()->getStoreId();
https://snipt.net/embed/9be96dfa336e0098f48770d1e3264fa8/
/raw/9be96dfa336e0098f48770d1e3264fa8/
9be96dfa336e0098f48770d1e3264fa8
php
PHP
4
2019-06-13T00:40:59
True
False
False
/api/public/snipt/21744/
magento-display-store-id
<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></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">// display store ID</span> </span><span id="L-4"><a name="L-4"></a><span class="k">echo</span> <span class="s2">&quot;Store ID = &quot;</span> <span class="o">.</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">getStore</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">getStoreId</span><span class="p">();</span> </span></pre></div> </td></tr></table>
magento