0

I'm trying to override the DefaultRenderer (commonly found when customer views their order in accounts) so I can do some customisations and include extra data.

I've managed to do this successfully, but when I view the order it doesn't show various bits of data which would normally appear without overriding. This includes item options, price, even SKU. It looks like this is anything with $block-> preceding it.

For example:

$block->prepareSku($block->getSku())

Gives me this error:

Invalid method Vendor\FancyOrder\Block\Item\Interceptor::prepareSku

If I remove this line, the order summary loads as expected, but with important information missing.

This is my block. I'm slowly getting used to module creation and dependency injection, so I have a feeling I've missed out some key things:

<?php
namespace Vendor\FancyOrder\Block;

use Magento\Catalog\Model\Product;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\Template;

class Item extends Template
{

    /**
     * @var Registry
     */
    protected $registry;
    protected $_imageBuilder;
    /**
     * @var Product
     */
    private $product;

    public function __construct(Template\Context $context,
                                Registry $registry,
                                \Magento\Catalog\Helper\Image $imageHelper,
                                \Magento\Catalog\Api\ProductRepositoryInterfaceFactory $productRepositoryFactory,
                                array $data)
    {
        $this->registry = $registry;
        $this->_imageHelper = $imageHelper;
        $this->_productRepositoryFactory = $productRepositoryFactory;

        parent::__construct($context, $data);
    }

    public function getTheImage($productID)
    {
        $product = $this->_productRepositoryFactory->create()->getById($productID);
        //return $this->_imageHelper->init($product,'thumbnail')->setImageFile($product->getThumbnail())->getUrl();

        $resized = $this->_imageHelper->init($product, 'product_small_image')
            ->constrainOnly(TRUE)
            ->keepAspectRatio(TRUE)
            ->keepTransparency(TRUE)
            ->keepFrame(FALSE)
            ->resize(200, 300);
        return $resized->getUrl();
    }
}

I have a feeling I need to declare the class in a different way, but I'm not sure how. I tried Class Item extends Magento\Sales\Block\Order\Item\Renderer but that errors.

Any information may help :)

Thank you!

Your Answer

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

Browse other questions tagged or ask your own question.