Jump to content

How are variables in product-list.tpl generated?


Recommended Posts

Hi

I am currently developing small custom module for specific shop. Basically I want to render one selected by admin product in style indentical as product card as in product-list.tpl but below left-column (I sent a screenshot to visualize this)

 

My question is from where product-list.tpl have these much infromations about products? When I create simple object from Product class I don't have anything that is required to render for example:

reduction,

discount_percentage,

discount_amount

cover

etc.

 

I stumbled accross this code that on the first sight gives another module required product information, but how can I modify it to just simple get product info by its id?

 

 $searchProvider = new BestSalesProductSearchProvider(
            $this->context->getTranslator()
        );

        $context = new ProductSearchContext($this->context);

        $query = new ProductSearchQuery();

        $query
            ->setResultsPerPage(1)
            ->setPage(1)
            
        ;

        $query->setSortOrder(SortOrder::random());

        $result = $searchProvider->runQuery(
            $context,
            $query
        );

        $assembler = new ProductAssembler($this->context);

        $presenterFactory = new ProductPresenterFactory($this->context);
        $presentationSettings = $presenterFactory->getPresentationSettings();
        $presenter = new ProductListingPresenter(
            new ImageRetriever(
                $this->context->link
            ),
            $this->context->link,
            new PriceFormatter(),
            new ProductColorsRetriever(),
            $this->context->getTranslator()
        );

        $products_for_template = array();

        foreach ($result->getProducts() as $rawProduct) {
            $products_for_template[] = $presenter->present(
                $presentationSettings,
                $assembler->assembleProduct($rawProduct),
                $this->context->language
            );
        }

        return $products_for_template;

 

presta-problem.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...