0

Hi I have some cross sells that appear after adding to basket, when setting the "position" attribute in the backend for each cross sell it does not affect their actual order frontend!

The code is

<?php if($_crossSellProducts = $_product->getCrossSellProducts()): ?>

What can I add to this to get $_product->getCrossSellProducts() in order of their position?

I tried the following but get a blank popup so obviously errors.

<?php if($_crossSellProducts = $_product->getCrossSellProducts()->addAttributeToSort('position')): ?>

Thanks!

1

It's because the method getCrossSellProducts returns an array an not a collection.

Try the following :

$_crossSellProducts = $_product->getCrossSellProductCollection()
            ->addAttributeToSort('position');

If you have many calls to this method in your page, I recommend you to use an observer on the before load for this collection.

|improve this answer|||||
  • Hi its just the one call, however I still get them showing not in position order :( <?php if($_crossSellProducts = $_product->getCrossSellProductCollection()->addAttributeToSort('position')): ?> – KiwisTasteGood Dec 15 '15 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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