Latest news

How To Get SKUs From Orders in Magento?

No comments

TASK: Getting all SKUs from orders of the user who is currently logged in in Magento

For Example:

A user has placed 3 orders.

  • 1st order contains SKUs: 0001, 0002 and 0003
  • 2nd order contains SKUs: 0002 and 0004
  • 3rd order contains SKUs: 0001, 0002 and 0005

How can we get the returned list of SKUs including: 0001, 0002, 0003, 0004 and 0005.

The aim of this is to create a list of all the products that the user has ordered in one page along with the product thumbnail, name and a link to the product page.

SOLUTIONS:

Step 1: Add new tab to My Account

<layout version="0.1.0">
...
<customer_account>
	<reference name="customer_account_navigation">
            <action method="addLink" translate="label" module="yourmodule">
                <name>name</name>
                <path>controller_of_custommodule</path>
                <label>Your Label</label>
            </action>
        </reference>
</customer_account>
<yourmodule_default>
	<update handle="page_two_columns_left" />
	<reference name="left_first">
          <block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
            <action method="addLink" translate="label" module="customer"><name>account</name><path>customer/account/</path><label>Account Dashboard</label></action>
            <action method="addLink" translate="label" module="customer"><name>account_edit</name><path>customer/account/edit/</path><label>Account Information</label></action>
            <action method="addLink" translate="label" module="customer"><name>address_book</name><path>customer/address/</path><label>Address Book</label></action>
            <action method="addLink" translate="label" module="sales"><name>orders</name><path>sales/order/history/</path><label>My Orders</label></action>
            <action method="addLink" translate="label" module="wishlist" ifconfig="wishlist/general/active"><name>wishlist</name><path>wishlist/</path><label>My Wishlist</label></action>
            <action method="addLink" translate="label" module="yourmodule">
              <name>name</name>
              <path>controller_of_custommodule</path>
              <label>Your Label</label>
            </action>
          </block>
        </reference>
</yourmodule_default>
<yourmodule_index_index>
	<update handle="yourmodule_default" />
	<reference name="content">
            <block type="yourmodule/nameblock" name="yourmodule.nameblock" template="yourmodule/yourtemplate.phtml"></block>
        </reference>
</yourmodule_index_index>
...
</layout>

Step 2: Create Block in your module:

<layout version="0.1.0">
...
<customer_account>
	<reference name="customer_account_navigation">
            <action method="addLink" translate="label" module="yourmodule">
                <name>name</name>
                <path>controller_of_custommodule</path>
                <label>Your Label</label>
            </action>
        </reference>
</customer_account>
<yourmodule_default>
	<update handle="page_two_columns_left" />
	<reference name="left_first">
          <block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
            <action method="addLink" translate="label" module="customer"><name>account</name><path>customer/account/</path><label>Account Dashboard</label></action>
            <action method="addLink" translate="label" module="customer"><name>account_edit</name><path>customer/account/edit/</path><label>Account Information</label></action>
            <action method="addLink" translate="label" module="customer"><name>address_book</name><path>customer/address/</path><label>Address Book</label></action>
            <action method="addLink" translate="label" module="sales"><name>orders</name><path>sales/order/history/</path><label>My Orders</label></action>
            <action method="addLink" translate="label" module="wishlist" ifconfig="wishlist/general/active"><name>wishlist</name><path>wishlist/</path><label>My Wishlist</label></action>
            <action method="addLink" translate="label" module="yourmodule">
              <name>name</name>
              <path>controller_of_custommodule</path>
              <label>Your Label</label>
            </action>
          </block>
        </reference>
</yourmodule_default>
<yourmodule_index_index>
	<update handle="yourmodule_default" />
	<reference name="content">
            <block type="yourmodule/nameblock" name="yourmodule.nameblock" template="yourmodule/yourtemplate.phtml"></block>
        </reference>
</yourmodule_index_index>
...
</layout>

Step 3: Create template and get data from your Block

 

See More Our Magento “How To” Series:

How To Configure Payment Methods In Magento 2 – Part 1

How To Create A Credit Memo In Magento 2

How To Create A Customer Group And Assign Customer To A Particular Group In Magento 2

How To Install A New Theme In Magento 2

How To Create A Custom Widget in Magento 2

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...
April LeeHow To Get SKUs From Orders in Magento?

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *