EC-CUBE3:個別税率(軽減税率)が商品詳細ページ、金額計算に反映されない点を解消

2019年9月2日に(1)について掲載しました。
その後、2019年10月4日にGitHub/EC-CUBEでの解消方法を確認しましたので、(3)にその情報を掲載します。
不具合を解消する場合は、(3)の方法で行うとよいでしょう。

既に、(1)の方法で修正されている場合は、(2)の方法で元にもどしてから、(3)の方法で修正を行ってください。

 

zeiritu

・ 商品別税率機能を有効
・ 税率一覧 ID:1の「編集」で税率を10%に変更

商品登録画面の「詳細な設定」に消費税率欄が表示されます。
軽減税率に該当する商品のみ、「8」を入力します。(入力しない商品は、10%が適用)

ところが、
個別税率(軽減税率)が商品詳細ページ、金額計算に反映されません。

この記事のインデックス

(1)次のファイルの修正で、正常な動作になります。

■src/Eccube/Repository/TaxRuleRepository.php
157行目付近、変更。

// Product
if ($Product && $productId > 0) {
$qb->andWhere('t.Product IS NULL OR t.Product = :Product');
$parameters['Product'] = $Product;
} else {
$qb->andWhere('t.Product IS NULL');
}

↓【修正】

// Product
if ($Product && $productId > 0) {
$qb->andWhere('t.Product IS NULL OR t.Product = :Product');
$parameters['Product'] = $Product;
// ▼個別税率設定が商品詳細ページに反映されない点を解消(下の2行を追加)
} else if ($ProductClass && $productClassId > 0) {
// ProductClassが渡ってきているが、$Productがnullのタイミングがあった時の対応
} else {
$qb->andWhere('t.Product IS NULL');
}

(2)上記の修正を元に戻す

下記の記述が(1)の修正で追加した部分なので、この部分を削除してください。
—————————————————–
// ▼個別税率設定が商品詳細ページに反映されない点を解消(下の2行を追加)
} else if ($ProductClass && $productClassId > 0) {
// ProductClassが渡ってきているが、$Productがnullのタイミングがあった時の対応
—————————————————–
↓【削除して元に戻す】

// Product
if ($Product && $productId > 0) {
$qb->andWhere('t.Product IS NULL OR t.Product = :Product');
$parameters['Product'] = $Product;
} else {
$qb->andWhere('t.Product IS NULL');
}

(3) 修正ファイルは同じです。

■src/Eccube/Repository/TaxRuleRepository.php

86行目付近に下記コードを追加します。
—————————————————————
// Product が null の場合は正常に税率取得できないため, Product を取得し直す
if ($ProductClass instanceof \Eccube\Entity\ProductClass && $Product === null) {
$this->getEntityManager()->refresh($ProductClass);
$Product = $ProductClass->getProduct();
}
—————————————————————
↓【結果、追加コードを含めた前後の記述】


// Pref Country 設定
 if (!$Pref && !$Country && $this->app['security']->getToken() && $this->app['security']->isGranted('ROLE_USER')) {
 /* @var $Customer \Eccube\Entity\Customer */
 $Customer = $this->app['security']->getToken()->getUser();
 $Pref = $Customer->getPref();
 $Country = $Customer->getCountry();
 }

// Product が null の場合は正常に税率取得できないため, Product を取得し直す
 if ($ProductClass instanceof \Eccube\Entity\ProductClass && $Product === null) {
 $this->getEntityManager()->refresh($ProductClass);
 $Product = $ProductClass->getProduct();
 }

 // 商品単位税率設定がOFFの場合
 /** @var $BaseInfo \Eccube\Entity\BaseInfo */
 $BaseInfo = $this->app['eccube.repository.base_info']->get();
 if ($BaseInfo->getOptionProductTaxRule() !== Constant::ENABLED) {
 $Product = null;
 $ProductClass = null;
 }

▼参考
https://github.com/EC-CUBE/ec-cube/pull/4310/files