Eccube3 カスタマイズ Cartに情報を記録する
2021年5月28日EcCube3にて、カート(CartItem)に情報を記述する際の作業メモです。
1.まずは以下のようにFormTypeを指示します
ファイル:src/Eccube/Form/Type/AddCartType.php
$builder->add(‘souryou3syu’, ‘text’, array(
‘label’ => ‘送料3種類’,
‘required’ => false,
));
2.つづけてControllerを指定します
ファイル:src/Eccube/Controller/ProductController.php
$app[‘eccube.service.cart’]->addProduct($addCartData[‘product_class_id’], $addCartData[‘quantity’], $addCartData[‘souryou3syu’])->save();
3.カートサービスに登録します。
ファイル:src/Eccube/Service/CartService.php
addProduct()関数
$this->setProductQuantity($productClassId, $quantity, $souryou3syu);
setProductQuantity()関数
if (!is_null($souryou3syu)) {
$CartItem->setSouryou3syu($souryou3syu);
}
4.さらに、エンティティにてカートアイテムに登録します。
ファイル:src/Eccube/Entity/CartItem.php
public function __sleep()
{
return array(‘class_name’, ‘class_id’, ‘price’, ‘quantity’,’souryou3syu’);
}
private $souryou3syu;
public function setSouryou3syu($souryou3syu){
$this->souryou3syu = $souryou3syu;
return $this;
}
5.カートコントローラーに表示
ファイル:src/Eccube/Controller/CartController.php
$Cart = $app[‘eccube.service.cart’]->getCart();
6.カート表示
ファイル:src/Eccube/Resource/template/default/Cart/index.twig
{% CartItem.souryou3syu %}