public function getNewShipmentItem(Order $Order, Product $Product, ProductClass $ProductClass, $quantity)
{
$ShipmentItem = new ShipmentItem();
$shippings = $Order->getShippings();
// 選択された商品がどのお届け先情報と関連するかチェック
$Shipping = null;
foreach ($shippings as $s) {
if ($s->getDelivery()->getProductType()->getId() == $ProductClass->getProductType()->getId()) {
// 商品種別が同一のお届け先情報と関連させる
$Shipping = $s;
break;
}
}
if (is_null($Shipping)) {
// お届け先情報と関連していない場合、エラー
throw new CartException('shopping.delivery.not.producttype');
}
// 商品ごとの配送料合計
$productDeliveryFeeTotal = 0;
if (!is_null($this->BaseInfo->getOptionProductDeliveryFee())) {
$productDeliveryFeeTotal = $ProductClass->getDeliveryFee() * $quantity;
}
$Shipping->setShippingDeliveryFee($Shipping->getShippingDeliveryFee() + $productDeliveryFeeTotal);
$ShipmentItem->setShipping($Shipping)->setOrder($Order)->setProductClass($ProductClass)->setProduct($Product)->setProductName($Product->getName())->setProductCode($ProductClass->getCode())->setPrice($ProductClass->getPrice02())->setQuantity($quantity);
$ClassCategory1 = $ProductClass->getClassCategory1();
if (!is_null($ClassCategory1)) {
$ShipmentItem->setClasscategoryName1($ClassCategory1->getName());
$ShipmentItem->setClassName1($ClassCategory1->getClassName()->getName());
}
$ClassCategory2 = $ProductClass->getClassCategory2();
if (!is_null($ClassCategory2)) {
$ShipmentItem->setClasscategoryName2($ClassCategory2->getName());
$ShipmentItem->setClassName2($ClassCategory2->getClassName()->getName());
}
$Shipping->addShipmentItem($ShipmentItem);
$this->em->persist($ShipmentItem);
return $ShipmentItem;
}