Beispiel #1
0
 /**
  * @param  \Eccube\Entity\CartItem $AddCartItem
  * @return \Eccube\Entity\Cart
  */
 public function setCartItem(\Eccube\Entity\CartItem $AddCartItem)
 {
     $find = false;
     foreach ($this->CartItems as $CartItem) {
         if ($CartItem->getClassName() === $AddCartItem->getClassName() && $CartItem->getClassId() === $AddCartItem->getClassId()) {
             $find = true;
             $CartItem->setPrice($AddCartItem->getPrice())->setQuantity($AddCartItem->getQuantity());
         }
     }
     if (!$find) {
         $this->addCartItem($AddCartItem);
     }
     return $this;
 }
Beispiel #2
0
 /**
  * @param  \Eccube\Entity\ProductClass|integer $ProductClass
  * @param  integer $quantity
  * @return \Eccube\Service\CartService
  * @throws CartException
  */
 public function setProductQuantity($ProductClass, $quantity)
 {
     if (!$ProductClass instanceof ProductClass) {
         $ProductClass = $this->entityManager->getRepository('Eccube\\Entity\\ProductClass')->find($ProductClass);
         if (!$ProductClass) {
             throw new CartException('cart.product.delete');
         }
     }
     if ($ProductClass->getProduct()->getStatus()->getId() !== Disp::DISPLAY_SHOW) {
         $this->removeProduct($ProductClass->getId());
         throw new CartException('cart.product.not.status');
     }
     $productName = $ProductClass->getProduct()->getName();
     if ($ProductClass->hasClassCategory1()) {
         $productName .= " - " . $ProductClass->getClassCategory1()->getName();
     }
     if ($ProductClass->hasClassCategory2()) {
         $productName .= " - " . $ProductClass->getClassCategory2()->getName();
     }
     // 商品種別に紐づく配送業者を取得
     $deliveries = $this->app['eccube.repository.delivery']->getDeliveries($ProductClass->getProductType());
     if (count($deliveries) == 0) {
         // 商品種別が存在しなければエラー
         $this->removeProduct($ProductClass->getId());
         $this->addError('cart.product.not.producttype', $productName);
         throw new CartException('cart.product.not.producttype');
     }
     $this->setCanAddProductType($ProductClass->getProductType());
     if ($this->BaseInfo->getOptionMultipleShipping() != Constant::ENABLED) {
         if (!$this->canAddProduct($ProductClass->getId())) {
             // 複数配送対応でなければ商品種別が異なればエラー
             throw new CartException('cart.product.type.kind');
         }
     } else {
         // 複数配送の場合、同一支払方法がなければエラー
         if (!$this->canAddProductPayment($ProductClass->getProductType())) {
             throw new CartException('cart.product.payment.kind');
         }
     }
     $tmp_subtotal = 0;
     $tmp_quantity = 0;
     foreach ($this->getCart()->getCartItems() as $cartitem) {
         $pc = $cartitem->getObject();
         if ($pc->getId() != $ProductClass->getId()) {
             // まず、追加された商品以外のtotal priceをセット
             $tmp_subtotal += $cartitem->getTotalPrice();
         }
     }
     for ($i = 0; $i < $quantity; $i++) {
         $tmp_subtotal += $ProductClass->getPrice02IncTax();
         if ($tmp_subtotal > $this->app['config']['max_total_fee']) {
             $this->setError('cart.over.price_limit');
             break;
         }
         $tmp_quantity++;
     }
     $quantity = $tmp_quantity;
     $tmp_quantity = 0;
     /*
      * 実際の在庫は ProductClass::ProductStock だが、購入時にロックがかかるため、
      * ここでは ProductClass::stock で在庫のチェックをする
      */
     if (!$ProductClass->getStockUnlimited() && $quantity > $ProductClass->getStock()) {
         if ($ProductClass->getSaleLimit() && $ProductClass->getStock() > $ProductClass->getSaleLimit()) {
             $tmp_quantity = $ProductClass->getSaleLimit();
             $this->addError('cart.over.sale_limit', $productName);
         } else {
             $tmp_quantity = $ProductClass->getStock();
             $this->addError('cart.over.stock', $productName);
         }
     }
     if ($ProductClass->getSaleLimit() && $quantity > $ProductClass->getSaleLimit()) {
         $tmp_quantity = $ProductClass->getSaleLimit();
         $this->addError('cart.over.sale_limit', $productName);
     }
     if ($tmp_quantity) {
         $quantity = $tmp_quantity;
     }
     $CartItem = new CartItem();
     $CartItem->setClassName('Eccube\\Entity\\ProductClass')->setClassId((string) $ProductClass->getId())->setPrice($ProductClass->getPrice02IncTax())->setQuantity($quantity);
     $this->cart->setCartItem($CartItem);
     return $this;
 }
Beispiel #3
0
 /**
  * @param  \Eccube\Entity\ProductClass|integer $ProductClass
  * @param  integer $quantity
  * @return \Eccube\Service\CartService
  * @throws CartException
  */
 public function setProductQuantity($ProductClass, $quantity)
 {
     if (!$ProductClass instanceof \Eccube\Entity\ProductClass) {
         $ProductClass = $this->entityManager->getRepository('Eccube\\Entity\\ProductClass')->find($ProductClass);
     }
     if (!$ProductClass || $ProductClass->getProduct()->getStatus()->getId() !== 1) {
         throw new CartException('cart.product.type.kind');
     }
     $this->setCanAddProductType($ProductClass->getProductType());
     if (!$this->canAddProduct($ProductClass->getId())) {
         throw new CartException('cart.product.type.kind');
     }
     if (!$ProductClass->getStockUnlimited() && $quantity > $ProductClass->getStock()) {
         $quantity = $ProductClass->getStock();
         $this->addError('cart.over.stock');
     } elseif ($ProductClass->getSaleLimit() && $quantity > $ProductClass->getSaleLimit()) {
         $quantity = $ProductClass->getSaleLimit();
         $this->addError('cart.over.sale_limit');
     }
     $CartItem = new CartItem();
     $CartItem->setClassName('Eccube\\Entity\\ProductClass')->setClassId((string) $ProductClass->getId())->setPrice($ProductClass->getPrice02IncTax())->setQuantity($quantity);
     $this->cart->setCartItem($CartItem);
     return $this;
 }
 /**
  * @param  \Eccube\Entity\ProductClass|integer $ProductClass
  * @param  integer $quantity
  * @return \Eccube\Service\CartService
  * @throws CartException
  */
 public function setProductQuantity($ProductClass, $quantity)
 {
     if (!$ProductClass instanceof \Eccube\Entity\ProductClass) {
         $ProductClass = $this->entityManager->getRepository('Eccube\\Entity\\ProductClass')->find($ProductClass);
     }
     if (!$ProductClass || $ProductClass->getProduct()->getStatus()->getId() !== Constant::ENABLED) {
         $this->removeProduct($ProductClass->getId());
         throw new CartException('cart.product.not.status');
     }
     $this->setCanAddProductType($ProductClass->getProductType());
     if ($this->BaseInfo->getOptionMultipleShipping() != Constant::ENABLED) {
         if (!$this->canAddProduct($ProductClass->getId())) {
             // 複数配送対応でなければ商品種別が異なればエラー
             throw new CartException('cart.product.type.kind');
         }
     } else {
         // 複数配送の場合、同一支払方法がなければエラー
         if (!$this->canAddProductPayment($ProductClass->getProductType())) {
             throw new CartException('cart.product.payment.kind');
         }
     }
     if (!$ProductClass->getStockUnlimited() && $quantity > $ProductClass->getStock()) {
         if ($ProductClass->getSaleLimit() && $ProductClass->getStock() > $ProductClass->getSaleLimit()) {
             $quantity = $ProductClass->getSaleLimit();
             $this->setError('cart.over.sale_limit');
         } else {
             $quantity = $ProductClass->getStock();
             $this->setError('cart.over.stock');
         }
     } elseif ($ProductClass->getSaleLimit() && $quantity > $ProductClass->getSaleLimit()) {
         $quantity = $ProductClass->getSaleLimit();
         $this->setError('cart.over.sale_limit');
     }
     $CartItem = new CartItem();
     $CartItem->setClassName('Eccube\\Entity\\ProductClass')->setClassId((string) $ProductClass->getId())->setPrice($ProductClass->getPrice02IncTax())->setQuantity($quantity);
     $this->cart->setCartItem($CartItem);
     return $this;
 }
Beispiel #5
0
 /**
  * @param  \Eccube\Entity\ProductClass|integer $ProductClass
  * @param  integer $quantity
  * @return \Eccube\Service\CartService
  * @throws CartException
  */
 public function setProductQuantity($ProductClass, $quantity)
 {
     if (!$ProductClass instanceof \Eccube\Entity\ProductClass) {
         $ProductClass = $this->entityManager->getRepository('Eccube\\Entity\\ProductClass')->find($ProductClass);
     }
     if (!$ProductClass || $ProductClass->getProduct()->getStatus()->getId() !== Constant::ENABLED) {
         $this->removeProduct($ProductClass->getId());
         throw new CartException('cart.product.not.status');
     }
     $this->setCanAddProductType($ProductClass->getProductType());
     if ($this->BaseInfo->getOptionMultipleShipping() != Constant::ENABLED) {
         if (!$this->canAddProduct($ProductClass->getId())) {
             // 複数配送対応でなければ商品種別が異なればエラー
             throw new CartException('cart.product.type.kind');
         }
     } else {
         // 複数配送の場合、同一支払方法がなければエラー
         if (!$this->canAddProductPayment($ProductClass->getProductType())) {
             throw new CartException('cart.product.payment.kind');
         }
     }
     $tmp_subtotal = 0;
     $tmp_quantity = 0;
     foreach ($this->getCart()->getCartItems() as $cartitem) {
         $pc = $cartitem->getObject();
         if ($pc->getId() != $ProductClass->getId()) {
             // まず、追加された商品以外のtotal priceをセット
             $tmp_subtotal += $cartitem->getTotalPrice();
         }
     }
     for ($i = 0; $i < $quantity; $i++) {
         $tmp_subtotal += $ProductClass->getPrice02IncTax();
         if ($tmp_subtotal > $this->app['config']['max_total_fee']) {
             $this->setError('cart.over.price_limit');
             break;
         }
         $tmp_quantity++;
     }
     $quantity = $tmp_quantity;
     $tmp_quantity = 0;
     $product_str = $ProductClass->getProduct()->getName();
     if ($ProductClass->hasClassCategory1()) {
         $product_str .= " - " . $ProductClass->getClassCategory1()->getName();
     }
     if ($ProductClass->hasClassCategory2()) {
         $product_str .= " - " . $ProductClass->getClassCategory2()->getName();
     }
     $this->session->getFlashBag()->set('eccube.front.request.product', $product_str);
     if (!$ProductClass->getStockUnlimited() && $quantity > $ProductClass->getStock()) {
         if ($ProductClass->getSaleLimit() && $ProductClass->getStock() > $ProductClass->getSaleLimit()) {
             $tmp_quantity = $ProductClass->getSaleLimit();
             $this->addError('cart.over.sale_limit');
         } else {
             $tmp_quantity = $ProductClass->getStock();
             $this->addError('cart.over.stock');
         }
     }
     if ($ProductClass->getSaleLimit() && $quantity > $ProductClass->getSaleLimit()) {
         $tmp_quantity = $ProductClass->getSaleLimit();
         $this->addError('cart.over.sale_limit');
     }
     if ($tmp_quantity) {
         $quantity = $tmp_quantity;
     }
     $CartItem = new CartItem();
     $CartItem->setClassName('Eccube\\Entity\\ProductClass')->setClassId((string) $ProductClass->getId())->setPrice($ProductClass->getPrice02IncTax())->setQuantity($quantity);
     $this->cart->setCartItem($CartItem);
     return $this;
 }