バージョン選択

フォーラム

メニュー

オンライン状況

32 人のユーザが現在オンラインです。 (26 人のユーザが フォーラム を参照しています。)
登録ユーザ: 0
ゲスト: 32
もっと...

サイト内検索

質問 > 管理機能 > 新着商品を登録した順番に5つの商品を表示するブロックが作成できません

管理機能

新規スレッドを追加する

スレッド表示 | 古いものから 前のトピック | 次のトピック | 下へ
投稿者 スレッド
shinra
投稿日時: 2023/11/15 13:06
対応状況: −−−
一人前
登録日: 2017/9/2
居住地:
投稿: 124
Re: 新着商品を登録した順番に5つの商品を表示するブロックが作成できません
検証はしていないですが
NewProductExtension.php
を下記にすれば良いかもしれないです

<?php

namespace Customize\Twig\Extension;

use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\EntityManagerInterface;
use Eccube\Common\EccubeConfig;
use Eccube\Entity\Master\ProductListOrderBy;
use Eccube\Repository\ProductRepository;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class NewProductExtension extends AbstractExtension
{
    /**
     * @var ProductRepository
     */
    private $productRepository;

    /**
     * @var EntityManagerInterface
     */
    private $entityManager;
    /**
     * @var EccubeConfig
     */
    private $eccubeConfig;

    public function __construct(
        ProductRepository $productRepository,
        EntityManagerInterface $entityManager,
        EccubeConfig $eccubeConfig
    )
    {
        $this->productRepository = $productRepository;
        $this->entityManager = $entityManager;
        $this->eccubeConfig = $eccubeConfig;
    }

    public function getFunctions(): array
    {
        return [
            new TwigFunction('newProducts', [$this, 'newProducts'], ['pre_escape' => 'html', 'is_safe' => ['html']]),
        ];
    }
    
    public function newProducts($limit)
    {
        /** @var ProductListOrderBy $productListOrderBy */
        $productListOrderBy = $this->entityManager->getRepository(ProductListOrderBy::class)->find($this->eccubeConfig['eccube_product_order_newer']);

        $qb = $this->productRepository->getQueryBuilderBySearchData(['orderby' => $productListOrderBy]);
        $qb
            ->setMaxResults($limit);

        return $qb->getQuery()->getResult();
    }
}
h_tanaka
投稿日時: 2023/9/19 12:49
対応状況: −−−
登録日: 2016/7/22
居住地: 愛媛県
投稿: 1650
Re: 新着商品を登録した順番に5つの商品を表示するブロックが作成できません
Twig 名をクラス名と同じにしているの怪しいので、 「NewProductExtension」を使用している箇所を洗い出してリネームしてみると良いかもしれません。


----------------
EC-CUBE 《プラチナ》ランクパートナー
トエビス株式会社 田中 宏典
EC-CUBEの機能やデザインのカスタマイズ承ります。

h_tanaka
投稿日時: 2023/9/19 12:44
対応状況: −−−
登録日: 2016/7/22
居住地: 愛媛県
投稿: 1650
Re: 新着商品を登録した順番に5つの商品を表示するブロックが作成できません
ソースコードがそのまま表示されてしまっているので、ただのコーディングミスとかだと思います。
上記に記載されているソースでは怪しいところ見受けられなかったので、デバッグしたり改修前のソースに戻したりして調査してみてください。


----------------
EC-CUBE 《プラチナ》ランクパートナー
トエビス株式会社 田中 宏典
EC-CUBEの機能やデザインのカスタマイズ承ります。

cusmix
投稿日時: 2023/9/15 23:03
対応状況: −−−
半人前
登録日: 2022/4/23
居住地:
投稿: 12
Re: 新着商品を登録した順番に5つの商品を表示するブロックが作成できません
実際のページを見ると、赤線で囲んだところのように表示されます。ご教示いただけますと幸いです。

https://imgur.com/a/AOUJQlO
h_tanaka
投稿日時: 2023/9/15 16:58
対応状況: −−−
登録日: 2016/7/22
居住地: 愛媛県
投稿: 1650
Re: 新着商品を登録した順番に5つの商品を表示するブロックが作成できません
できない、というのはどのような表示になるのでしょうか?


----------------
EC-CUBE 《プラチナ》ランクパートナー
トエビス株式会社 田中 宏典
EC-CUBEの機能やデザインのカスタマイズ承ります。

cusmix
投稿日時: 2023/9/15 16:11
対応状況: −−−
半人前
登録日: 2022/4/23
居住地:
投稿: 12
新着商品を登録した順番に5つの商品を表示するブロックが作成できません
▼テンプレート
[EC-CUBE] EC-CUBE 4.0.4
[OS] Windows10
[PHP] php7.4
[データベース] MySQL XAMPP 7.4.19
[ブラウザ] Chrome最新バージョン
[導入プラグインの有無] なし
[カスタマイズの有無] なし
[現象]
Windowsでローカル開発環境構築したEC-CUBEで新着商品を登録した順番に5つの商品を表示するブロックを作成したいのですができません。
app/Customize/Twig/Extension/NewProductExtension.php を作成しました。
<?php

namespace Customize\Twig\Extension;

use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\EntityManagerInterface;
use Eccube\Common\EccubeConfig;
use Eccube\Entity\Master\ProductListOrderBy;
use Eccube\Repository\ProductRepository;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class NewProductExtension extends AbstractExtension
{
    /**
     * @var ProductRepository
     */
    private $productRepository;

    /**
     * @var EntityManagerInterface
     */
    private $entityManager;
    /**
     * @var EccubeConfig
     */
    private $eccubeConfig;

    public function __construct(
        ProductRepository $productRepository,
        EntityManagerInterface $entityManager,
        EccubeConfig $eccubeConfig
    )
    {
        $this->productRepository = $productRepository;
        $this->entityManager = $entityManager;
        $this->eccubeConfig = $eccubeConfig;
    }

    public function getFunctions(): array
    {
        return [
            new TwigFunction('newProducts', function ($limit) {

                /** @var ProductListOrderBy $productListOrderBy */
                $productListOrderBy = $this->entityManager->getRepository(ProductListOrderBy::class)->find($this->eccubeConfig['eccube_product_order_newer']);

                $qb = $this->productRepository->getQueryBuilderBySearchData(['orderby' => $productListOrderBy]);
                $qb
                    ->setMaxResults($limit);

                return $qb->getQuery()->getResult();
            }, ['pre_escape' => 'html', 'is_safe' => ['html']]),
        ];
    }
}


更に、ブロックを作成して、
Twig名をNewProductExtension5.twigとして、
{% set Products = newProducts(5) %}
 
<div class="ec-role">
    <div class="ec-newItemRole">
        <div class="ec-newItemRole__list">
            <div class="ec-newItemRole__listItem">
                <div class="ec-newItemRole__listItemHeading ec-secHeading--tandem">
                    <span class="ec-secHeading__en">{{ 'front.block.new_item.title__en'|trans }}</span>
                    <span class="ec-secHeading__line"></span>
                    <span class="ec-secHeading__ja">{{ 'front.block.new_item.title__ja'|trans }}</span>
                    <a class="ec-inlineBtn--top" href="{{ url('product_list') }}?orderby={{eccube_config.eccube_product_order_newer}}">{{ 'front.block.new_item.more'|trans }}</a>
                </div>
            </div>
             
            {% for Product in Products %}
            <div class="ec-newItemRole__listItem">
                <a href="{{ url('product_detail', {'id': Product.id}) }}">
                    <img src="{{ asset(Product.main_list_image|no_image_product, 'save_image') }}">
                    <p class="ec-newItemRole__listItemTitle">{{ Product.name }}</p>
                    <p class="ec-newItemRole__listItemPrice">
                    {% if Product.hasProductClass %}
                        {% if Product.getPrice02Min == Product.getPrice02Max %}
                            {{ Product.getPrice02IncTaxMin|price }}
                        {% else %}
                            {{ Product.getPrice02IncTaxMin|price }} ~ {{ Product.getPrice02IncTaxMax|price }}
                        {% endif %}
                    {% else %}
                        {{ Product.getPrice02IncTaxMin|price }}
                    {% endif %}
                    </p>
                </a>
            </div>
            {% endfor %}
 
        </div>
    </div>
</div>

このブロックをトップページに配置したのですが、
productRepository = $productRepository; $this->entityManager = $entityManager; $this->eccubeConfig = $eccubeConfig; } public function getFunctions(): array { return [ new TwigFunction('newProducts', function ($limit) { /** @var ProductListOrderBy $productListOrderBy */ $productListOrderBy = $this->entityManager->getRepository(ProductListOrderBy::class)->find($this->eccubeConfig['eccube_product_order_newer']); $qb = $this->productRepository->getQueryBuilderBySearchData(['orderby' => $productListOrderBy]); $qb ->setMaxResults($limit); return $qb->getQuery()->getResult(); }, ['pre_escape' => 'html', 'is_safe' => ['html']]), ]; } }

と表示されてしまいます。
どのようにしたら、最新登録した商品5個を表示するブロックを作成することができるのでしょうか?
お手数と思いますが、どなたか教えていただけるとありがたいです。
スレッド表示 | 古いものから 前のトピック | 次のトピック | トップ


 



ログイン


EC-CUBE公式 Amazon Payプラグイン

統計情報

総メンバー数は89,168名です
総投稿数は110,047件です

投稿数ランキング

1
seasoft
7367
2
468
3217
3
AMUAMU
2712
4
nanasess
2314
5
umebius
2085
6
yuh
1819
7
h_tanaka
1650
8
red
1570
9
mcontact
1299
10
tsuji
958
11
fukap
907
12
shutta
835
13
tao_s
799
14 ramrun 789
15 karin 689
16 sumida 641
17
homan
633
18 DELIGHT 572
19
patapata
502
20
flealog
485


ネットショップの壺

EC-CUBEインテグレートパートナー

Copyright© EC-CUBE CO.,LTD. All Rights Reserved.