1

I want You may also like section on order at the end. The content on order page comes from sales/order/items.phtml file. I want to call the "you may also like" section in this file, the You may also like section comes from product/list/upsell.phtml file. Now I want to call this section in sales/order/items.phtml file I also tried to make changes in xml file. How can I get this?

<sales_order_view translate="label">
    <label>Customer My Account Order View</label>
    <update handle="customer_account"/>
    <reference name="my.account.wrapper">
        <block type="sales/order_info" as="info" name="sales.order.info">
            <block type="sales/order_info_buttons" as="buttons" name="sales.order.info.buttons" />
        </block>
        <block type="sales/order_view" name="sales.order.view">
            <block type="sales/order_items" name="order_items" template="sales/order/items.phtml">
                <action method="addItemRender"><type>default</type><block>sales/order_item_renderer_default</block><template>sales/order/items/renderer/default.phtml</template></action>
                <action method="addItemRender"><type>grouped</type><block>sales/order_item_renderer_grouped</block><template>sales/order/items/renderer/default.phtml</template></action>
                <block type="sales/order_totals" name="order_totals" template="sales/order/totals.phtml">
                    <action method="setLabelProperties"><value>colspan="4" class="a-right"</value></action>
                    <action method="setValueProperties"><value>class="last a-right"</value></action>
                    <block type="tax/sales_order_tax" name="tax" template="tax/order/tax.phtml" />
                </block>
                <block type="product/list_upsell" name="upsell_products" template="product/list/upsell.phtml" />
            </block>
        </block>
    </reference>
    <reference name="sales.order.info">
        <action method="addLink" translate="label" module="sales"><name>view</name><path></path><label>Order Information</label></action>
        <action method="addLink" translate="label" module="sales"><name>invoice</name><path>*/*/invoice</path><label>Invoices</label></action>
        <action method="addLink" translate="label" module="sales"><name>shipment</name><path>*/*/shipment</path><label>Shipments</label></action>
        <action method="addLink" translate="label" module="sales"><name>creditmemo</name><path>*/*/creditmemo</path><label>Refunds</label></action>
    </reference>
    <block type="core/text_list" name="additional.product.info" translate="label">
        <label>Additional Product Info</label>
    </block>
</sales_order_view>
  • Your need is to display the upsells block in sales/order/items.phtml ? – PЯINCƏ Aug 10 '17 at 8:36
  • @Prince Yes..exactly..! – Sushant Thorat Aug 10 '17 at 8:41
  • @Prince, How can I achieve this, Any solution? – Sushant Thorat Aug 10 '17 at 8:44
  • Look my answer please – PЯINCƏ Aug 10 '17 at 8:55
1

Up-sells for a product are items that you would like your customer to buy instead of the product that he is viewing, natively this block is displayed in catalog/product/view.phtml

Now you want to display this upsells block in sales/order/items.phtml you have to do this:

1) app/design/frontend/{package}/{theme}/layout/local.xml add this code :

<sales_order_view>
    <reference name="root">
        <block type="catalog/product_list_upsell" name="product.info.upsell" as="upsell_products" template="catalog/product/list/upsell.phtml">
            <action method="setColumnCount"><columns>6</columns></action>
            <action method="setItemLimit"><type>upsell</type><limit>6</limit></action>
        </block>
    </reference>
</sales_order_view>

2) app/design/frontend/{package}/{theme}/template/sales/order/items.phtml add this code where you want to display this new upsells block :

<?php echo $this->getBlockHtml('product.info.upsell') ?>

EDIT:

As I explained at the beginning of my answer the upsells are related to minimum one product! and the upsells block have Mage_Catalog_Block_Product_List_Upsell class and he can't get a principal product where you are trying to display it in sales/order/view because you haven't any product !

So the first part of layout that i gave you is correct, now the second part you have to customise Mage_Catalog_Block_Product_List_Upsell please follow this solution

EDIT 2 :

You have to customise it according your need, please replace the _prepareData() of the rewrited one with the code bellow

protected function _prepareData()
    {
        $myProductId = 704; // here you put the product id that you have related the upsells on it
        $product = Mage::getModel('catalog/product')->load($myProductId);
        /* @var $product Mage_Catalog_Model_Product */
        $this->_itemCollection = $product->getUpSellProductCollection()
            ->setPositionOrder()
            ->addStoreFilter()
        ;
        if (Mage::helper('catalog')->isModuleEnabled('Mage_Checkout')) {
            Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection,
                Mage::getSingleton('checkout/session')->getQuoteId()
            );

            $this->_addProductAttributesAndPrices($this->_itemCollection);
        }
//        Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->_itemCollection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_itemCollection);

        if ($this->getItemLimit('upsell') > 0) {
            $this->_itemCollection->setPageSize($this->getItemLimit('upsell'));
        }

        $this->_itemCollection->load();

        /**
         * Updating collection with desired items
         */
        Mage::dispatchEvent('catalog_product_upsell', array(
            'product'       => $product,
            'collection'    => $this->_itemCollection,
            'limit'         => $this->getItemLimit()
        ));

        foreach ($this->_itemCollection as $product) {
            $product->setDoNotUseCategoryId(true);
        }

        return $this;
    }
  • Error occured..:( Call to a member function getUpSellProductCollection() on null – Sushant Thorat Aug 10 '17 at 8:59
  • yes it's logic because you haven't any product related to the upsells, look my edit please – PЯINCƏ Aug 10 '17 at 9:37
  • Still not getting :( – Sushant Thorat Aug 10 '17 at 10:07
  • Look my update please. – PЯINCƏ Aug 10 '17 at 11:09
  • ,And what to change in item.phtml and local.xml? – Sushant Thorat Aug 10 '17 at 11:20

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.