0

How can I show last order view on my customer panel dashboard? by default it shows last orders... I want to show last order view(detail) on dashboard. finally i tried this code

foreach ($_order->getAllVisibleItems() as $_item) {
     echo $block->escapeHtml($_item->getName());
} 

but have a problem, when i have 3 items in one order id it shows like item1 item2 item3. i want to show item1 item2 item3... with image of product. any help?

Now used this code but still cant see all product images, just shows one of them...

<?php foreach ($_order->getAllVisibleItems() as $_item) {
                        echo "Order date: " . $block->formatDate($_order->getCreatedAt());
                        $_imagehelper = $this->helper('Magento\Catalog\Helper\Image');
                        if($childProd = current($_item->getChildrenItems())){
                            $productImage = $_imagehelper->init($childProd->getProduct(), 'category_page_list', array('height' => 156 , 'width'=> 170))->getUrl();
                        }
                        else{
                            $productImage = $_imagehelper->init($_item->getProduct(), 'category_page_list', array('height' => 156 , 'width'=> 170))->getUrl();
                        }

                    }
                    ?>
1
  • share your phtml file code where you want to display product image. Commented May 15, 2019 at 6:13

1 Answer 1

0

In your block file Add below code :

public function getOrderItems()
{        
    $order_items = [];
    foreach ($_order->getAllVisibleItems() as $_item) {
            $order_items[] = $_item;
    }
    return $order_items;
}

In your phtml file add below code :

$productCollection = $block->getOrderItems();
$viewMode = 'list';
$_imageHelper = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Catalog\Helper\Image');

if (count($productCollection)){ ?>

<div class="page-title-wrapper" id="trending-product-list">
    <h2 class="page-title">
        <span class="base" data-ui-id="page-title-wrapper"><?php echo __('Welcome to Feedback page'); ?></span>
    </h2>
</div>
<div class="custom-review products-wrapper <?php echo $viewMode; ?> products-<?php echo $viewMode; ?>">
    <ol class="products list items product-items">
        <?php foreach ($productCollection as $product): ?>
        <?php if(in_array($product->getProductType(), $block->getProductTypes())){ ?>
        <li class="item product product-item" style="padding-bottom: 45px;">
            <div class="product-item-info" data-container="product-grid">                
                <a href="" class="product photo product-item-photo" tabindex="-1">
                    <span class="product-image-container" style="width:240px;">
                        <span class="product-image-wrapper" style="padding-bottom: 125%;">
                            <img class="product-image-wrapper" src="<?= $_imageHelper->init($product->getProduct(), 'small_image', ['type'=>'small_image'])->keepAspectRatio(true)->resize('240','300')->getUrl();?>" alt="<?= __('Product Image');?>">
                        </span>
                    </span>                    
                </a>
                <div class="product details product-item-details">
                    <strong class="product name product-item-name">
                        <a class="product-item-link"
                           href="<?php /* @escapeNotVerified */ echo$block->getProductUrl($product->getProductId()); ?>">
                               <?php /* @escapeNotVerified */ echo $product->getName(); ?>
                        </a>
                    </strong>                       
                </div>
            </div>
        </li>
            <?php } endforeach; ?>
    </ol>
</div>
<?php }else{ echo 'No product item found'; } ?>

Note : Do note use objectmanager.

I hope it helps!

7
  • Thanks, but it just shows image of one item not all items... i want to show each product image in one order
    – MGPM
    Commented May 15, 2019 at 9:20
  • You have to put this code in foreach loop phtml Commented May 15, 2019 at 10:35
  • Could you please give me code? i used into <?php foreach ($_order->getAllVisibleItems() as $_item) { but it goes to blank page with no code
    – MGPM
    Commented May 15, 2019 at 12:29
  • share your block & phtml file code so I can help you similarly. Don't worry you can share your code in your question. Commented May 15, 2019 at 12:48
  • Updated question
    – MGPM
    Commented May 16, 2019 at 5:16

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.