<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Agence de Développement Informatique du Nord &#187; magento</title>
	<atom:link href="http://blog.adin.pro/tag/magento/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.adin.pro</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Thu, 26 Dec 2019 08:54:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.1</generator>
	<item>
		<title>Magento &#8211; all you need about website / store / view</title>
		<link>http://blog.adin.pro/2015-09-24/magento-all-you-need-about-website-store-view/</link>
		<comments>http://blog.adin.pro/2015-09-24/magento-all-you-need-about-website-store-view/#comments</comments>
		<pubDate>Thu, 24 Sep 2015 08:41:07 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[store]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=500</guid>
		<description><![CDATA[<p>The post <a rel="nofollow" href="http://blog.adin.pro/2015-09-24/magento-all-you-need-about-website-store-view/">Magento &#8211; all you need about website / store / view</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<pre class="brush: php; title: ; notranslate">
// Gets the current store's details
$store = Mage::app()-&gt;getStore();
 
// Gets the current store's id
$storeId = Mage::app()-&gt;getStore()-&gt;getStoreId();
 
// Gets the current store's code
$storeCode = Mage::app()-&gt;getStore()-&gt;getCode();
 
// Gets the current website's id
$websiteId = Mage::app()-&gt;getStore()-&gt;getWebsiteId();
 
// Gets the current store's group id
$storeGroupId = Mage::app()-&gt;getStore()-&gt;getGroupId();
 
// Gets the current store's name
$storeName = Mage::app()-&gt;getStore()-&gt;getName();
 
// Gets the current store's sort order
$storeSortOrder = Mage::app()-&gt;getStore()-&gt;getSortOrder();
 
// Gets the current store's status
$storeIsActive = Mage::app()-&gt;getStore()-&gt;getIsActive();
 
// Gets the current store's locale
$storeLocaleCode = Mage::app()-&gt;getStore()-&gt;getLocaleCode();
 
// Gets the current store's home url
$storeHomeUrl = Mage::app()-&gt;getStore()-&gt;getHomeUrl();

//load store by code or id
$store = Mage::getModel('core/store')-&gt;load($code); //you can use code or id

</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2015-09-24/magento-all-you-need-about-website-store-view/">Magento &#8211; all you need about website / store / view</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2015-09-24/magento-all-you-need-about-website-store-view/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento &#8211; How to get current router module controller action ?</title>
		<link>http://blog.adin.pro/2015-01-09/magento-how-to-get-current-router-module-controller-action/</link>
		<comments>http://blog.adin.pro/2015-01-09/magento-how-to-get-current-router-module-controller-action/#comments</comments>
		<pubDate>Fri, 09 Jan 2015 11:35:06 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[magento]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=439</guid>
		<description><![CDATA[<p>You can easily know &#8220;where you are&#8221; using these fonctions : in template / block files in class files</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2015-01-09/magento-how-to-get-current-router-module-controller-action/">Magento &#8211; How to get current router module controller action ?</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>You can easily know &#8220;where you are&#8221; using these fonctions :</p>
<p>in template / block files</p>
<pre class="brush: php; title: ; notranslate">
$this-&gt;getRequest()-&gt;getRouteName();
$this-&gt;getRequest()-&gt;getModuleName();
$this-&gt;getRequest()-&gt;getControllerName();
$this-&gt;getRequest()-&gt;getActionName();
</pre>
<p>in class files</p>
<pre class="brush: php; title: ; notranslate">
Mage::app()-&gt;getRequest()-&gt;getRouteName();
Mage::app()-&gt;getRequest()-&gt;getModuleName();
Mage::app()-&gt;getRequest()-&gt;getControllerName();
Mage::app()-&gt;getRequest()-&gt;getActionName();
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2015-01-09/magento-how-to-get-current-router-module-controller-action/">Magento &#8211; How to get current router module controller action ?</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2015-01-09/magento-how-to-get-current-router-module-controller-action/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry &#8216;000000254&#8217; for key &#8216;UNQ_SALES_FLAT_ORDER_INCREMENT_ID&#8217;</title>
		<link>http://blog.adin.pro/2014-12-02/magento-sqlstate23000-integrity-constraint-violation-1062-duplicate-entry-000000254-for-key-unq_sales_flat_order_increment_id/</link>
		<comments>http://blog.adin.pro/2014-12-02/magento-sqlstate23000-integrity-constraint-violation-1062-duplicate-entry-000000254-for-key-unq_sales_flat_order_increment_id/#comments</comments>
		<pubDate>Tue, 02 Dec 2014 10:11:12 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[increment_id]]></category>
		<category><![CDATA[magento]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=427</guid>
		<description><![CDATA[<p>In some cases, customers encounter this error on your website : You don&#8217;t understand and drive you crazy ? Don&#8217;t worry, I will help you. First, this error probably happend when customer quit violenty the payment page, without canceling, so &#8230; <a href="http://blog.adin.pro/2014-12-02/magento-sqlstate23000-integrity-constraint-violation-1062-duplicate-entry-000000254-for-key-unq_sales_flat_order_increment_id/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-12-02/magento-sqlstate23000-integrity-constraint-violation-1062-duplicate-entry-000000254-for-key-unq_sales_flat_order_increment_id/">Magento SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry &#8216;000000254&#8217; for key &#8216;UNQ_SALES_FLAT_ORDER_INCREMENT_ID&#8217;</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>In some cases, customers encounter this error on your website :</p>
<pre class="brush: php; title: ; notranslate">
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '000000254' for key 'UNQ_SALES_FLAT_ORDER_INCREMENT_ID'
</pre>
<p>You don&#8217;t understand and drive you crazy ?<br />
Don&#8217;t worry, I will help you.</p>
<p>First, this error probably happend when customer quit violenty the payment page, without canceling, so your order is not &#8220;finished&#8221; and your quote is not &#8220;released&#8221; (is_active = 1 in db). Customer come back, recover his quote and try to proceed it again.<br />
The reserved_increment_id is not updated and when magento try to create the order, mySQL give him the previous error.</p>
<p>How a so obvious bug like this can exist ? and why does it crash only on my website, it seems to work fine on other website ?<br />
Let me guest, your client (clients always have weird needs &#8230;) ask you to start order number at 0 instead of 100000000, or ask you to put a letter into it.</p>
<p>So, why does this reserved_increment_id is not updated ?<br />
Let check on the function which update the reserved_increment_id field :</p>
<pre class="brush: php; title: ; notranslate">
// /app/code/core/Mage/Sales/Model/Resource/Quote.php
    /**
     * Check is order increment id use in sales/order table
     *
     * @param int $orderIncrementId
     * @return boolean
     */
    public function isOrderIncrementIdUsed($orderIncrementId)
    {
        $adapter   = $this-&gt;_getReadAdapter();
        $bind      = array(':increment_id' =&gt; (int)$orderIncrementId);
        $select    = $adapter-&gt;select();
        $select-&gt;from($this-&gt;getTable('sales/order'), 'entity_id')
            -&gt;where('increment_id = :increment_id');
        $entity_id = $adapter-&gt;fetchOne($select, $bind);
        if ($entity_id &gt; 0) {
            return true;
        }

        return false;
    }
</pre>
<p>You see it, the little (int) in this line $bind      = array(&#8216;:increment_id&#8217; => (int)$orderIncrementId); ?<br />
This transform your increment_id in your request from &#8220;000000254&#8221; to &#8220;254&#8221;, mySQL doesn&#8217;t find an order with the increment_id &#8220;254&#8221; and your quote is not updated.</p>
<p>To fix it, override this function :<br />
In your Sales/etc/config.xml file, add</p>
<pre class="brush: xml; title: ; notranslate">
&lt;global&gt;
  &lt;model&gt;
    &lt;sales_resource&gt;
                &lt;rewrite&gt;
                    &lt;quote&gt;Adin_Sales_Model_Resource_Sales_Quote&lt;/quote&gt;
                &lt;/rewrite&gt;
            &lt;/sales_resource&gt;
   &lt;/model&gt;
&lt;/global&gt;
</pre>
<p>And create the new class file /app/code/local/Adin/Sales/Model/Resource/Sales/Quote.php</p>
<pre class="brush: php; title: ; notranslate">
class Adin_Sales_Model_Resource_Sales_Quote extends Mage_Sales_Model_Resource_Quote {

    /**
     * Check is order increment id use in sales/order table
     *
     * @param int $orderIncrementId
     * @return boolean
     */
    public function isOrderIncrementIdUsed($orderIncrementId)
    {
        $adapter   = $this-&gt;_getReadAdapter();
        $bind      = array(':increment_id' =&gt; $orderIncrementId);
        $select    = $adapter-&gt;select();
        $select-&gt;from($this-&gt;getTable('sales/order'), 'entity_id')
            -&gt;where('increment_id = :increment_id');
        $entity_id = $adapter-&gt;fetchOne($select, $bind);
        if ($entity_id &gt; 0) {
            return true;
        }

        return false;
    }

}
</pre>
<p>That should do the tricks.</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-12-02/magento-sqlstate23000-integrity-constraint-violation-1062-duplicate-entry-000000254-for-key-unq_sales_flat_order_increment_id/">Magento SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry &#8216;000000254&#8217; for key &#8216;UNQ_SALES_FLAT_ORDER_INCREMENT_ID&#8217;</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2014-12-02/magento-sqlstate23000-integrity-constraint-violation-1062-duplicate-entry-000000254-for-key-unq_sales_flat_order_increment_id/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento : how to get current user ?</title>
		<link>http://blog.adin.pro/2014-09-24/magento-how-to-get-current-user/</link>
		<comments>http://blog.adin.pro/2014-09-24/magento-how-to-get-current-user/#comments</comments>
		<pubDate>Wed, 24 Sep 2014 12:49:14 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[adminhtml]]></category>
		<category><![CDATA[current user]]></category>
		<category><![CDATA[magento]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=407</guid>
		<description><![CDATA[<p>Need to get the current user in magneto ? Here how to. Frontend : Backend :</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-09-24/magento-how-to-get-current-user/">Magento : how to get current user ?</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Need to get the current user in magneto ?<br />
Here how to.</p>
<p>Frontend :</p>
<pre class="brush: php; title: ; notranslate">
if(Mage::getSingleton('customer/session')-&gt;isLoggedIn())
{
     Mage::getSingleton('customer/session')-&gt;getCustomer();
}
//or
Mage::helper('customer')-&gt;getCustomerName();
</pre>
<p>Backend :</p>
<pre class="brush: php; title: ; notranslate">
$user = Mage::getSingleton('admin/session')-&gt;getUser();
//bonus : roles
$uer-&gt;getRoles();
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-09-24/magento-how-to-get-current-user/">Magento : how to get current user ?</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2014-09-24/magento-how-to-get-current-user/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento link in backend redirect to dashboard</title>
		<link>http://blog.adin.pro/2014-09-22/magento-link-in-backend-redirect-to-dashboard/</link>
		<comments>http://blog.adin.pro/2014-09-22/magento-link-in-backend-redirect-to-dashboard/#comments</comments>
		<pubDate>Mon, 22 Sep 2014 09:18:51 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[dashboard]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[magento]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=404</guid>
		<description><![CDATA[<p>You are working on Magento backoffice and make a link to a new page but when you click on your anchor, you are redirected to the dashboard ? Here how to make a proper link : Something like doesn&#8217;t work, &#8230; <a href="http://blog.adin.pro/2014-09-22/magento-link-in-backend-redirect-to-dashboard/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-09-22/magento-link-in-backend-redirect-to-dashboard/">Magento link in backend redirect to dashboard</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>You are working on Magento backoffice and make a link to a new page but when you click on your anchor, you are redirected to the dashboard ?</p>
<p>Here how to make a proper link :</p>
<pre class="brush: php; title: ; notranslate">
   echo &quot;&lt;a href='&quot;.Mage::helper('adminhtml')-&gt;getUrl('*/*/displaydetail', array('id' =&gt; $cour['id'])).&quot;' &gt;&quot;.$cour['name'].&quot;&lt;/a&gt;&quot;;
</pre>
<p>Something like </p>
<pre class="brush: php; title: ; notranslate">
 Mage::getUrl('*/*/displaydetail/id/'.$cour['id'])
</pre>
<p>doesn&#8217;t work, even if I had the FormKey. But you can use it for ajax request</p>
<pre class="brush: jscript; title: ; notranslate">
 jQuery.ajax({
        url: &quot;&lt;?php echo Mage::getUrl('*/*/classroomfromplaceAjax') ?&gt;&quot;,
        type: &quot;POST&quot;,
        dataType: 'json',
        data: 'place_id=' + place_id + '&amp;index=' + index + '&amp;form_key=' + window.FORM_KEY,
        success: function (data) {
            jQuery('#classroom_' + index).html(data.html);
        },
    });
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-09-22/magento-link-in-backend-redirect-to-dashboard/">Magento link in backend redirect to dashboard</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2014-09-22/magento-link-in-backend-redirect-to-dashboard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento force store_id session</title>
		<link>http://blog.adin.pro/2014-05-20/magento-force-store_id-session/</link>
		<comments>http://blog.adin.pro/2014-05-20/magento-force-store_id-session/#comments</comments>
		<pubDate>Tue, 20 May 2014 09:50:38 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=385</guid>
		<description><![CDATA[<p>This is how to force or change magento store_id into the session</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-05-20/magento-force-store_id-session/">Magento force store_id session</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>This is how to force or change magento store_id into the session</p>
<pre class="brush: php; title: ; notranslate">
// Start store emulation process
$appEmulation = Mage::getSingleton('core/app_emulation');
$initialEnvironmentInfo = $appEmulation-&gt;startEnvironmentEmulation($storeId);
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-05-20/magento-force-store_id-session/">Magento force store_id session</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2014-05-20/magento-force-store_id-session/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento custom sort on grid &#8211; sort increment_id by numeric not alpha</title>
		<link>http://blog.adin.pro/2014-04-30/magento-custom-sort-on-grid-sort-increment_id-by-numeric-not-alpha/</link>
		<comments>http://blog.adin.pro/2014-04-30/magento-custom-sort-on-grid-sort-increment_id-by-numeric-not-alpha/#comments</comments>
		<pubDate>Wed, 30 Apr 2014 07:42:04 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=381</guid>
		<description><![CDATA[<p>You can easily filter column in a magento grid (see my previous post) but customize a sort is a little bit more hand made. In this example in the order grid, I want to sort by increment_id, but this is &#8230; <a href="http://blog.adin.pro/2014-04-30/magento-custom-sort-on-grid-sort-increment_id-by-numeric-not-alpha/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-04-30/magento-custom-sort-on-grid-sort-increment_id-by-numeric-not-alpha/">Magento custom sort on grid &#8211; sort increment_id by numeric not alpha</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>You can easily filter column in a magento grid (see my previous post) but customize a sort is a little bit more hand made.</p>
<p>In this example in the order grid, I want to sort by increment_id, but this is a text fields and I want to sort it by numeric.</p>
<p>default sort : 1, 10, 100, 2, 3 &#8230;<br />
numeric sort : 1, 2, 3, 10, 100 &#8230;</p>
<p>If you look the SQL request, you got this</p>
<pre class="brush: php; title: ; notranslate">
SELECT `main_table`.* FROM `sales_flat_order_grid` AS `main_table` ORDER BY increment_id DESC LIMIT 20
</pre>
<p>To tell MySQL to sort this text column by numeric, you can add &#8220;+ 0&#8243; to the ORDER BY clause, this will transform the text field into numeric field</p>
<pre class="brush: php; title: ; notranslate">
SELECT `main_table`.* FROM `sales_flat_order_grid` AS `main_table` ORDER BY increment_id + 0 DESC LIMIT 20
</pre>
<p>Now, how to tell Magento to add &#8220;+ 0&#8243; to this sort ?</p>
<p>Override your grid class and modify the &#8220;_setCollectionOrder($column)&#8221; function.</p>
<pre class="brush: php; title: ; notranslate">
class Adin_Sales_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid {
    protected function _setCollectionOrder($column)
    {
        $collection = $this-&gt;getCollection();
        if ($collection) {
            $columnIndex = $column-&gt;getFilterIndex() ? $column-&gt;getFilterIndex() : $column-&gt;getIndex();
            if($columnIndex == 'increment_id')
            {
                $columnIndex = 'increment_id + 0';
            }
            $collection-&gt;setOrder($columnIndex, strtoupper($column-&gt;getDir()));
        }
        return $this;
    }
}
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-04-30/magento-custom-sort-on-grid-sort-increment_id-by-numeric-not-alpha/">Magento custom sort on grid &#8211; sort increment_id by numeric not alpha</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2014-04-30/magento-custom-sort-on-grid-sort-increment_id-by-numeric-not-alpha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento custom filter on grid</title>
		<link>http://blog.adin.pro/2014-04-25/magento-custom-filter-on-grid/</link>
		<comments>http://blog.adin.pro/2014-04-25/magento-custom-filter-on-grid/#comments</comments>
		<pubDate>Fri, 25 Apr 2014 14:09:44 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[magento]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=378</guid>
		<description><![CDATA[<p>Sometimes, you need a special column on your grid from another table or with some calculation. It works well, column is displayed but filter doesn&#8217;t work. Here a small example how to customize your filter : On your grid class &#8230; <a href="http://blog.adin.pro/2014-04-25/magento-custom-filter-on-grid/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-04-25/magento-custom-filter-on-grid/">Magento custom filter on grid</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Sometimes, you need a special column on your grid from another table or with some calculation.<br />
It works well, column is displayed but filter doesn&#8217;t work.<br />
Here a small example how to customize your filter :</p>
<p>On your grid class (Adin_Sponsorship_Block_Adminhtml_Sponsorship_Grid.class.php), override your _prepareColumns() function</p>
<pre class="brush: php; title: ; notranslate">
protected function _prepareColumns()
{
        $this-&gt;addColumn('sponsor_email', array(
                'header'    =&gt; Mage::helper('evian_customer')-&gt;__('Sponsor Email'),
                'index'     =&gt; 'sponsor_email',
                'align'     =&gt; 'center',
                'filter_condition_callback' =&gt; array($this, '_filterSponsortEmail'),
            )
        );
}
</pre>
<p>The &#8216;filter_condition_callback&#8217; option indicates to use as filter a specific method, on the current class ($this) the method _filterSponsortEmail().</p>
<p>So next step, create this method.</p>
<pre class="brush: php; title: ; notranslate">
    protected function _filterSponsortEmail($collection, $column)
    {
        if (!$value = trim($column-&gt;getFilter()-&gt;getValue())) {
            return;
        }
        $this-&gt;getCollection()-&gt;addFieldToFilter('customer.email', array('like' =&gt; '%'.$value.'%'));
    }
</pre>
<p>Yes, this is this simple.</p>
<p>If you use a datetime column, it&#8217;s just a bit more complicated, see below</p>
<pre class="brush: php; title: ; notranslate">
        $this-&gt;addColumn('created_at', array(
            'header'    =&gt; Mage::helper('evian_customer')-&gt;__('Date of sponsorship'),
            'index'     =&gt; 'created_at',
            'align'     =&gt; 'center',
            'type' =&gt; 'datetime',
            'filter_condition_callback' =&gt; array($this, '_filterDate'),
            )
        );
</pre>
<p>and the filter method</p>
<pre class="brush: php; title: ; notranslate">
    protected function _filterDate($collection, $column)
    {
        $filters = $column-&gt;getFilter()-&gt;getValue();

            $from = $filters['from'];
            $to = $filters['to'];


       $this-&gt;getCollection()-&gt;addFieldToFilter('main_table.created_at', array('gteq' =&gt; $from-&gt;toString('yyyy-MM-dd')));
        $this-&gt;getCollection()-&gt;addFieldToFilter('main_table.created_at', array('lteq' =&gt; $to-&gt;toString('yyyy-MM-dd')));
    }
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-04-25/magento-custom-filter-on-grid/">Magento custom filter on grid</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2014-04-25/magento-custom-filter-on-grid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento filter products collection get only visible</title>
		<link>http://blog.adin.pro/2014-04-17/magento-filter-products-collection-get-only-visible/</link>
		<comments>http://blog.adin.pro/2014-04-17/magento-filter-products-collection-get-only-visible/#comments</comments>
		<pubDate>Thu, 17 Apr 2014 07:28:46 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[deprecated]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[product]]></category>
		<category><![CDATA[visibility]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=374</guid>
		<description><![CDATA[<p>You want to retrieve all your products but only the one visible in catalog or filter ? You may use this But it&#8217;s depreacated and doesn&#8217;t work. You may instead use this :</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-04-17/magento-filter-products-collection-get-only-visible/">Magento filter products collection get only visible</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>You want to retrieve all your products but only the one visible in catalog or filter ?</p>
<p>You may use this </p>
<pre class="brush: php; title: ; notranslate">
 $collection = Mage::getModel('catalog/product')-&gt;getCollection()-&gt;addAttributeToSelect('*');
 Mage::getSingleton('catalog/product_status')-&gt;addVisibleFilterToCollection($collection);
 Mage::getSingleton('catalog/product_visibility')-&gt;addVisibleInCatalogFilterToCollection($collection);
</pre>
<p>But it&#8217;s depreacated and doesn&#8217;t work.<br />
You may instead use this :</p>
<pre class="brush: php; title: ; notranslate">
 $collection = Mage::getModel('catalog/product')-&gt;getCollection()-&gt;addAttributeToSelect('*');
 $collection-&gt;addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-04-17/magento-filter-products-collection-get-only-visible/">Magento filter products collection get only visible</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2014-04-17/magento-filter-products-collection-get-only-visible/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento multi fields validator for RIB</title>
		<link>http://blog.adin.pro/2014-02-28/magento-multi-fields-validator-for-rib/</link>
		<comments>http://blog.adin.pro/2014-02-28/magento-multi-fields-validator-for-rib/#comments</comments>
		<pubDate>Fri, 28 Feb 2014 08:56:34 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[RIB]]></category>
		<category><![CDATA[validator]]></category>
		<category><![CDATA[VarienForm]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=360</guid>
		<description><![CDATA[<p>Magento come with a great form validator : VarienForm. These is a lot of existing validator, for every usage and you can easyly add some. This is how you can do it with a commun example, how to check RIB &#8230; <a href="http://blog.adin.pro/2014-02-28/magento-multi-fields-validator-for-rib/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-02-28/magento-multi-fields-validator-for-rib/">Magento multi fields validator for RIB</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Magento come with a great form validator : VarienForm. These is a lot of existing validator, for every usage and you can easyly add some. This is how you can do it with a commun example, how to check RIB bank account.</p>
<p>First, our html code</p>
<pre class="brush: xml; title: ; notranslate">
&lt;ul class=&quot;inlineblockli&quot;&gt;
	&lt;li&gt;
		&lt;label for=&quot;code_bank_pb&quot;&gt;&lt;?php echo $this-&gt;__('bank code') ?&gt;&lt;/label&gt;
                &lt;input type=&quot;text&quot; class=&quot;inputText inputTextB validate-digits required-entry validate-length minimum-length-5 maximum-length-5&quot; id=&quot;code_bank_pb&quot; maxlength=&quot;5&quot; name=&quot;prelevement[code_bank_pb]&quot;&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;label for=&quot;code_guichet_pb&quot;&gt;&lt;?php echo $this-&gt;__('branch code') ?&gt;&lt;/label&gt;
                &lt;input type=&quot;text&quot; class=&quot;inputText inputTextB validate-digits required-entry validate-length minimum-length-5 maximum-length-5&quot; id=&quot;code_guichet_pb&quot; maxlength=&quot;5&quot; name=&quot;prelevement[code_guichet_pb]&quot;&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;label for=&quot;num_compte&quot;&gt;&lt;?php echo $this-&gt;__('Account number to be debited') ?&gt;&lt;/label&gt;
                &lt;input type=&quot;text&quot; class=&quot;inputText inputTextBig3 validate-digits required-entry validate-length minimum-length-11 maximum-length-11&quot; id=&quot;num_compte&quot; maxlength=&quot;11&quot; name=&quot;prelevement[num_compte]&quot;&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;label for=&quot;key_rib&quot;&gt;&lt;?php echo $this-&gt;__('RIB key') ?&gt;&lt;/label&gt;
                &lt;input type=&quot;text&quot; class=&quot;inputText inputTextSm3 validate-digits required-entry validate-compte validate-length minimum-length-2 maximum-length-2&quot; id=&quot;key_rib&quot; maxlength=&quot;2&quot; name=&quot;prelevement[key_rib]&quot;&gt;
	&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>We first do a lenght validation with these 3 class : validate-length minimum-length-11 maximum-length-11</p>
<p>Then we validate the rib with this class : validate-compte<br />
You will tell me this validator doesn&#8217;t exeist. That&#8217;s right, let&#8217;s create it.</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;
    //&lt;![CDATA[
    Validation.addAllThese(
        [
            ['validate-compte', '&lt;?php echo Mage::helper('rating')-&gt;__('Please check your RIB account') ?&gt;', function(v) {
                var code_banque = jQuery('#code_bank_pb').val();
                var code_guichet = jQuery('#code_guichet_pb').val();
                var numero_compte = jQuery('#num_compte').val();
                var cle           = jQuery('#key_rib').val();

                var CompteTmp = code_banque + code_guichet + numero_compte + cle;

                while(CompteTmp.length &gt; 9)
                {
                    var CompteTmp2 = CompteTmp.substr(0,9) % 97;
                    CompteTmp = CompteTmp2 + CompteTmp.substr(9,CompteTmp.length);
                }
                var CompteTmp2 = CompteTmp.substr(0,9) % 97;

                if(CompteTmp2 % 97 == 0)
                {
                    return true;
                }
                return false;
            }]
        ]
    );
    //]]&gt;
&lt;/script&gt;
</pre>
<p>Some explainations :</p>
<pre class="brush: jscript; title: ; notranslate">
jQuery('#code_bank_pb').val();
</pre>
<p>Magento use prototype, tu use jQuery, use jQuery instead of $</p>
<p>For the multi field validation, I grab the different fields from this</p>
<pre class="brush: jscript; title: ; notranslate">
var code_banque   = jQuery('#code_bank_pb').val();
var code_guichet  = jQuery('#code_guichet_pb').val();
var numero_compte = jQuery('#num_compte').val();
var cle           = jQuery('#key_rib').val();
</pre>
<p>I don&#8217;t know if this is the cleaner way to do (not really usable for another code) but it works.<br />
If you always use the same input id, you can reuse this code on another site.</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-02-28/magento-multi-fields-validator-for-rib/">Magento multi fields validator for RIB</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2014-02-28/magento-multi-fields-validator-for-rib/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
