0
 <p>{{block type="catalog/product_list" 
           column_count="4" 
           category_id="13" 
           template="catalog/product/list.phtml"}}</p>

我在magento 1.x版本中使用了上面的代码,在首页显示分类产品

更新到 Magento 2.0 版后,上面的代码不再工作了。

我该如何纠正它?

4

5 回答 5

1

{{widget type="Magento\CatalogWidget\Block\Product\ProductsList"
         products_count="4" 
        template="product/widget/content/grid.phtml"
        conditions_encoded="a:2:[i:1;a:4:[s:4:`type`;    s:50:`Magento|CatalogWidget|Model|Rule|Condition|Combine`;s:10:`aggregator`;s:3:`all`;s:5:`value`;s:1:`1`;s:9:`new_child`;s:0:``;]s:4:`1--1`;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Product`;s:9:`attribute`;s:12:`category_ids`;s:8:`operator`;s:2:`==`;s:5:`
            value`;s:1:`13`;]]"}}

上面代码最后一行,13代表类别id,根据需要更改category_id

于 2015-12-18T09:13:49.817 回答
0

尝试这个

<?php
$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();        
$categoryFactory = $objectManager->get('\Magento\Catalog\Model\CategoryFactory');
$categoryHelper = $objectManager->get('\Magento\Catalog\Helper\Category');
$categoryRepository = $objectManager->get('\Magento\Catalog\Model\CategoryRepository');
$priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data'); 
$productmodel = $objectManager->create('Magento\Catalog\Block\Product\ListProduct'); 
?>
<div class="worldcup-deals">
                <div class="deals-baaner">
                    <img src='<?php echo $this->getViewFileUrl('images/worldcup/2.png'); ?>' alt="deal-banner">
                </div>
                <div class="deals-products">
                    <div class="category-product-listing-world">
                        <?php 
                        $bestsamrtphoneid = 6685; 
                        $category = $categoryFactory->create()->load($bestsamrtphoneid);
                        $samrtphonecategoryProducts = $category->getProductCollection()
                        ->addAttributeToSelect('*');
                        $samrtphonecategoryProducts->getSelect()->order('RAND()');
                        $samrtphonecategoryProducts->getSelect()->limit(8);
                        //->setPageSize(8) // only get 10 products 
                        //->setCurPage(1);
                        ?>
                        <?php foreach ($samrtphonecategoryProducts as $product) { ?>
                        <div class="product-listing-world-item">
                            <?php 
                            $imagehelper = $objectManager->create('Magento\Catalog\Helper\Image');
                            $image = $imagehelper->init($product,'category_page_list')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(300, 300)->getUrl();
                            ?>
                            <div class="inner-world-wrap">
                                <a href="<?php echo $product->getProductUrl(); ?>">
                                    <img src="<?php echo $image; ?>">
                                </a>
                                <h3 class="product-name">
                                    <a href="<?php echo $product->getProductUrl(); ?>">
                                        <?php echo $product->getName() ?>
                                    </a>
                                </h3>
                                <?php echo $productmodel->getProductPrice($product);?>

                                <div class="shop-new">
                                    <a href="<?php echo $product->getProductUrl(); ?>">
                                        <?php echo __('Shop now >'); ?>
                                    </a>
                                    <img src="<?php echo $this->getViewFileUrl('images/demo/demo.png'); ?>">
                                </div>
                            </div>
                        </div>
                        <?php } ?>
                    </div>  
                    <a class="view" href="https://avechi.com/wakilisha-world-cup/cool-phones.html" target="_blank">view more >></a>
                </div>                       
            </div>
于 2018-07-05T09:15:36.353 回答
0

试试这个代码

<p>{{widget type="Magento\CatalogWidget\Block\Product\ProductsList" title="CTlog" show_pager="1" products_per_page="5" products_count="10" template="product/widget/content/grid.phtml" conditions_encoded="a:1:[i:1;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Combine`;s:10:`aggregator`;s:3:`all`;s:5:`value`;s:1:`1`;s:9:`new_child`;s:0:``;]]" page_var_name="pmqabw"}}</p>
于 2017-04-24T09:23:32.210 回答
0

尝试这个

{{block type="core/template" column_count="4" category_id="13" template="catalog/product/list.phtml"}}

之后转到 yourtheme/catalog/product/list.phtml 然后尝试在此文件顶部打印或回显

希望它会起作用

于 2015-12-16T06:26:14.520 回答
0

{{widget type="Magento\CatalogWidget\Block\Product\ProductsList"
         products_count="4" 
        template="product/widget/content/grid.phtml"
        conditions_encoded="a:2:[i:1;a:4:[s:4:`type`;    s:50:`Magento|CatalogWidget|Model|Rule|Condition|Combine`;s:10:`aggregator`;s:3:`all`;s:5:`value`;s:1:`1`;s:9:`new_child`;s:0:``;]s:4:`1--1`;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Product`;s:9:`attribute`;s:12:`category_ids`;s:8:`operator`;s:2:`==`;s:5:`
            value`;s:1:`13`;]]"}}

于 2017-04-24T06:04:19.117 回答