第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

PrestaShop:如何從我的產(chǎn)品中獲取 ProductListingLazyArray

PrestaShop:如何從我的產(chǎn)品中獲取 ProductListingLazyArray

PHP
紅顏莎娜 2023-07-30 13:13:11
我對(duì) PrestaShop 還很陌生 - 抱歉,如果我問(wèn)一些基本的問(wèn)題我目前正在開(kāi)發(fā)一個(gè)模塊,該模塊應(yīng)將您在后端選擇的產(chǎn)品顯示為默認(rèn)產(chǎn)品模板中的附加部分 - 例如“強(qiáng)烈推薦的產(chǎn)品”我完成了整個(gè)后端部分,并獲取 ID 作為所選產(chǎn)品的數(shù)組。正如我提到的,我想使用全新安裝后可用的默認(rèn)模板,我發(fā)現(xiàn)的模板放置在此處themes\classic\templates\catalog\_partials\products.tpl?,F(xiàn)在我的大問(wèn)題是:我無(wú)法獲得應(yīng)有的數(shù)據(jù)......如果我調(diào)試?yán)缒J(rèn)搜索行為中顯示的產(chǎn)品(這也使用此模板),我會(huì)看到類(lèi)似的內(nèi)容object(PrestaShop\PrestaShop\Adapter\Presenter\Product\ProductListingLazyArray)#323 (11) { ["imageRetriever":"Pr .....但當(dāng)我得到我的產(chǎn)品時(shí)new Product($productId, true);它不是 ProductListingLazyArray ...它只是一個(gè)包含產(chǎn)品的數(shù)組...并且我在前端沒(méi)有看到任何內(nèi)容(當(dāng)然我沒(méi)有看到,因?yàn)槔鐊$product.id_product}在我的數(shù)組中看起來(lái)不像這樣...您有什么想法可以將我的產(chǎn)品數(shù)組“轉(zhuǎn)換”為 ProductListingLazyArray 嗎?還是我的想法錯(cuò)了?謝謝大家!
查看完整描述

1 回答

?
慕婉清6462132

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超2個(gè)贊

解決方案

我只是“偽造”搜索并檢查數(shù)據(jù)是否在我的數(shù)組中:


/**

 * creates relevant product information for frontend output

 * 

 * @param array $allSelectedProductIds array with all id's of the selected products 

 * @param int $languageId language id of the shop you are in

 * 

 * @return array all product information we need for our frontend rendering

 */

public function getFrontendProductInformation($allSelectedProductIds, $languageId)

{

    // set default category Home

    $category = new Category((int)2);


    // create new product search proider

    $searchProvider = new CategoryProductSearchProvider(

        $this->context->getTranslator(),

        $category

    );


    // set actual context

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


    // create new search query

    $query = new ProductSearchQuery();

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

    $query->setSortOrder(new SortOrder('product', 'position', 'asc'));


    $result = $searchProvider->runQuery(

        $context,

        $query

    );


    // Product handling - to get relevant data

    $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 = array();

    foreach ($result->getProducts() as $rawProduct) {

        $productId = $rawProduct['id_product'];

        if(in_array($productId, $allSelectedProductIds)) {

            $product = $presenter->present(

                $presentationSettings,

                $assembler->assembleProduct($rawProduct),

                $this->context->language

            );

            array_push($products, $product);

        }

    }


    return $products;

}


查看完整回答
反對(duì) 回復(fù) 2023-07-30
  • 1 回答
  • 0 關(guān)注
  • 115 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)