snipt

Ctrl+h for KB shortcuts

PHP

Magento: update custom product attrib

<?php

// update a custom attribute in 1 product:
// 
$product = Mage::getModel('catalog/product')
    ->setCurrentStore(1)
    ->load($entity_id);

// note: the 3rd param is the store id
$product->addAttributeUpdate('rbanh_custom_attrib', $value, 1);
https://snipt.net/embed/cde8ff3f71243c7810282decc55a6769/
/raw/cde8ff3f71243c7810282decc55a6769/
cde8ff3f71243c7810282decc55a6769
php
PHP
10
2019-08-21T20:08:50
True
False
False
/api/public/snipt/17884/
magento-update-custom-product-attrib
<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> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</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">// update a custom attribute in 1 product:</span> </span><span id="L-4"><a name="L-4"></a><span class="c1">// </span> </span><span id="L-5"><a name="L-5"></a><span class="nv">$product</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><span id="L-6"><a name="L-6"></a> <span class="o">-&gt;</span><span class="na">setCurrentStore</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> </span><span id="L-7"><a name="L-7"></a> <span class="o">-&gt;</span><span class="na">load</span><span class="p">(</span><span class="nv">$entity_id</span><span class="p">);</span> </span><span id="L-8"><a name="L-8"></a> </span><span id="L-9"><a name="L-9"></a><span class="c1">// note: the 3rd param is the store id</span> </span><span id="L-10"><a name="L-10"></a><span class="nv">$product</span><span class="o">-&gt;</span><span class="na">addAttributeUpdate</span><span class="p">(</span><span class="s1">&#39;rbanh_custom_attrib&#39;</span><span class="p">,</span> <span class="nv">$value</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span> </span></pre></div> </td></tr></table>
magento, products