snipt

Ctrl+h for KB shortcuts

PHP

Category product inventory

1
2
3
4
<?php $stock_count = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
if ($stock_count <= 2) {
echo '<span class="numLeft">'.$stock_count.'</span>';
} ?>
https://snipt.net/embed/26dfe0678ede33119b712626d429e0c2/
/raw/26dfe0678ede33119b712626d429e0c2/
26dfe0678ede33119b712626d429e0c2
php
PHP
4
2019-08-10T11:07:53
True
False
False
/api/public/snipt/26920/
category-product-inventory
<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 class="nv">$stock_count</span> <span class="o">=</span> <span class="p">(</span><span class="nx">int</span><span class="p">)</span> <span class="nx">Mage</span><span class="o">::</span><span class="na">getModel</span><span class="p">(</span><span class="s1">&#39;cataloginventory/stock_item&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">loadByProduct</span><span class="p">(</span><span class="nv">$_product</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">getQty</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">$stock_count</span> <span class="o">&lt;=</span> <span class="mi">2</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a><span class="k">echo</span> <span class="s1">&#39;&lt;span class=&quot;numLeft&quot;&gt;&#39;</span><span class="o">.</span><span class="nv">$stock_count</span><span class="o">.</span><span class="s1">&#39;&lt;/span&gt;&#39;</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="p">}</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
magento

PHP

magento newsletter snippet

1
2
3
4
5
Snippet for newsletter magento

{{var subscriber.CustomerFirstname}}
{{var subscriber.CustomerLastname}}
{{var subscriber.SubscriberEmail}} 
https://snipt.net/embed/8b12c18889545a70985949d635579420/
/raw/8b12c18889545a70985949d635579420/
8b12c18889545a70985949d635579420
php
PHP
5
2019-07-29T06:36:00
True
False
False
/api/public/snipt/24531/
magento-newsletter-snippet
<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="x">Snippet for newsletter magento</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="x">{{var subscriber.CustomerFirstname}}</span> </span><span id="L-4"><a name="L-4"></a><span class="x">{{var subscriber.CustomerLastname}}</span> </span><span id="L-5"><a name="L-5"></a><span class="x">{{var subscriber.SubscriberEmail}} </span> </span></pre></div> </td></tr></table>
magento

PHP

Magento: Get last_insert_id in custom query

1
2
3
4
5
6
7
<?php
$connection = Mage::getSingleton('core/resource')->getConnection('core_write');
$sql        = "INSERT INTO <table> SET field1 = ?, field2 = ?, ...";
$connection->query($sql, array($field1_value, $field2_value, ...));
$lastInsertId = $connection->lastInsertId();
echo $lastInsertId; 
?>
https://snipt.net/embed/3940eff2a4c2608aa65cf2d8a5aa0921/
/raw/3940eff2a4c2608aa65cf2d8a5aa0921/
3940eff2a4c2608aa65cf2d8a5aa0921
php
PHP
7
2019-08-01T09:46:19
True
False
False
/api/public/snipt/24443/
magento-get-last_insert_id-in-custom-query
<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><span id="L-2"><a name="L-2"></a><span class="nv">$connection</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;core/resource&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">getConnection</span><span class="p">(</span><span class="s1">&#39;core_write&#39;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="nv">$sql</span> <span class="o">=</span> <span class="s2">&quot;INSERT INTO &lt;table&gt; SET field1 = ?, field2 = ?, ...&quot;</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="nv">$connection</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="nv">$sql</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span><span class="nv">$field1_value</span><span class="p">,</span> <span class="nv">$field2_value</span><span class="p">,</span> <span class="o">...</span><span class="p">));</span> </span><span id="L-5"><a name="L-5"></a><span class="nv">$lastInsertId</span> <span class="o">=</span> <span class="nv">$connection</span><span class="o">-&gt;</span><span class="na">lastInsertId</span><span class="p">();</span> </span><span id="L-6"><a name="L-6"></a><span class="k">echo</span> <span class="nv">$lastInsertId</span><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