May 30, 2017

6 questions need to clarify before implement a new payment method in Magento

I have worked with some new payment gateway to implement new payment method for Magento (both Magento 1.x and 2.x). So now I have experience before start to implement. As a developer, you should get answer 6 questions from payment gateway via the client. It should be:


  1. A possibility of doing an authorization hold, unhold (voiding), and capture for the bank cards.
  2. A possibility to refund a payment from the Mangento backend.
  3. A possibility of a partial refund.
  4. A possibility to pay an order in the Magento backend.
  5. A possibility to limit a payment method's visibility by a customer's country OR a minimum and maximum order amount.
  6. A possibility to assign custom metadata to a payment transaction (an order's ID, a website URL, etc.).
Hope it can help you before start.


June 9, 2016

Orders do not show up in Your Account > Order History

My customers place orders, and when they go to the Your Account > Order History section of their account, the orders do not show up while admin can see in the back-end.

After investigating I seen that order has been NOT completed payment in payment gateway. So the payment module set the order state is "pending_payment". Looking Mage_Sales module we will see list of order state defined in app/code/core/Mage/Sales/etc/config.xml

<config>
    <global>
        <sales>
            <order>
                <states>
                    <new translate="label">
                        <label>New</label>
                        <statuses>
                            <pending default="1"/>
                        </statuses>
                        <visible_on_front>1</visible_on_front>
                    </new>
                    <pending_payment translate="label">
                        <label>Pending Payment</label>
                        <statuses>
                            <pending_payment default="1"/>
                        </statuses>
                    </pending_payment>
you will notice this state does not have a <visible_on_front>1</visible_on_front> node

So the solution is change order status to processing or allow this state to be shown. For the second option you can use the following: 

<config>
    <global>
        <sales>
            <order>
                <states>
                    <pending_payment translate="label">
                        <visible_on_front>1</visible_on_front>
                    </pending_payment>
                </states>
            </order>
        </sales>
    </global>
</config>
in your own custom extension's etc/config.xml file.

March 10, 2016

Magento EE synchronize data and configurations between a staging and a main website


From "Scheduler Timeline" dashboard in Magento EE 1.x I saw a cron name "enterprise_staging_automates". This cron runs every minute.

Back to Magento EE features, Magento EE allows you to create staging sites, and merge them at a certain date/time

Look around Magento core I discover module Enterprise_Staging that handles Content Staging inside enterprise (effectively allowing you to duplicate the store and views and preview changes). The following code automate:

public function automates() { try { $currentDate = Mage::getModel('core/date')->gmtDate(); $collection = Mage::getResourceModel('enterprise_staging/staging_collection') ->addIsSheduledToFilter(); foreach ($collection as $staging) { $applyDate = $staging->getMergeSchedulingDate(); if ($currentDate >= $applyDate) { $mapData = $staging->getMergeSchedulingMap(); if (!empty($mapData)) { $mapper = $staging->getMapperInstance()->unserialize($mapData); if ($mapper->getIsBackup()) { $staging->backup(); } $staging->setIsMegreByCron(true); $staging->merge(); } } } } catch (Enterprise_Staging_Exception $e) {} }
To achieve this function we need to add a staging website in install_dir/staging folder of Magento directory. We can add a staging website in System > Content staging menu. After creating a staging website, this cron will sync the data form main website to staging website from time to time.

Did you try this?
 

February 18, 2016

Git merge a specific commit in current branch



You can use git cherry-pick to apply a single commit by itself to your current branch.

Example: git cherry-pick d42c389f

June 17, 2015

Wordpress define your javascript right way

Sometime you see in Wordpress line of code like: wp_enqueue_script( 'swfobject' );

This is the way to call javascript already in Wordpress but how to define it? I will help you to use it.

Have many ways to insert external javascript file into Wordpress theme. But you should use way below to register new javascript file and add it to your template when needed.

Here is code:

Firstly, use "wp_register_script" function to define your file:

wp_register_script( 'qtobject', plugins_url('/path/to/your/file.js'), array(), '1.0.0' );

"qtobject" is script name handle

Then enqueues script anywhere in template:

wp_enqueue_script( 'qtobject' );

January 28, 2015

[Linux] CHMOD – how to change file permission

chmod 777 config.php
Available permission type: (below is not command)
First number is for the owner, second for the group, and third for everyone.
7 = Read + Write + Execute
6 = Read + Write
5 = Read + Execute
4 = Read
3 = Write + Execute
2 = Write
1 = Execute
0 = All access denied
There was an error in this gadget