0

the sidebar "recently ordered" show last order, but I don't get the order of product.

For example, here I have three products: C... M... S... (it's in french, so I show only the first letter).

The sidebar show in this order: S C M

Why, and how I can change it ?I already search, but it's difficult to find this specific question.

I want to have the sidebar show recently order products order by name, so result would be:

C M S

I can try to explain it better if you don't understand.

Edit : I find the phtml file at :

C:/wamp64/www/market-eurecia/vendor/magento/module-sales/view/frontend/templates/reorder/sidebar.phtml

But i don't know how it work, i find the databind with the foreach, but don't know how to change the order.

4
  • Means you need to change order of that product which put in single order? Aug 23, 2017 at 10:08
  • I need to order them by name, sorry i edit the post Aug 23, 2017 at 14:01
  • you need identify phtml file which called there and make sorting there. Aug 24, 2017 at 4:29
  • hi thanks, i find it on : C:/wamp64/www/market-eurecia/vendor/magento/module-sales/view/frontend/templates/reorder/sidebar.phtml But i don't know where i need to change something to change the order. Aug 24, 2017 at 12:22

1 Answer 1

0

There are at least two possible ways to do this, either with js or with php

The file vendor/magento/module-sales/view/frontend/templates/reorder/sidebar.phtml pulls the data (data-bind="scope: 'lastOrderedItems'") from a knockout view vendor/magento/module-sales/view/frontend/web/js/view/last-ordered-items.js

Using the js approach, in the knockout view we can see:

this.lastOrderedItems = customerData.get('last-ordered-items');

for (item in this.lastOrderedItems.items) {
    if (item['is_saleable']) {
        isShowAddToCart = true;
        break;
    }
}

So there we could sort the this.lastOrderedItems to meet our needs

To use the php approach we'd have to look at the dataProvider which we can see defined in the di.xml:

    <type name="Magento\Customer\CustomerData\SectionPoolInterface">
        <arguments>
            <argument name="sectionSourceMap" xsi:type="array">
                <item name="last-ordered-items" xsi:type="string">Magento\Sales\CustomerData\LastOrderedItems</item>
            </argument>
        </arguments>
    </type>

So when we check the file vendor/magento/module-sales/CustomerData/LastOrderedItems.php we can see an order collection loaded with a sort definition:

$orders = $this->_orderCollectionFactory->create()
    ->addAttributeToFilter('customer_id', $customerId)
    ->addAttributeToFilter('status', ['in' => $this->_orderConfig->getVisibleOnFrontStatuses()])
    ->addAttributeToSort('created_at', 'desc')
    ->setPage(1, 1);

It's recommended to override/extend core files, so to do any of those changes you would create a custom module

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.