Exemplo n.º 1
0
 /**
  * @param array $options
  *
  * @return FormView
  */
 public function getItemFormView(array $options = array())
 {
     $cartItem = $this->cartItemFactory->createNew();
     $this->orderItemQuantityModifier->modify($cartItem, 1);
     $form = $this->formFactory->create('sylius_cart_item', $cartItem, $options);
     return $form->createView();
 }
Exemplo n.º 2
0
 /**
  * @param CartItemEvent $event
  */
 public function addItem(CartItemEvent $event)
 {
     $cart = $event->getCart();
     $item = $event->getItem();
     foreach ($cart->getItems() as $existingItem) {
         if ($item->equals($existingItem)) {
             $this->orderItemQuantityModifier->modify($existingItem, $existingItem->getQuantity() + $item->getQuantity());
             return;
         }
     }
     $cart->addItem($item);
 }
 /**
  * {@inheritdoc}
  */
 public function mapFormsToData($forms, &$data)
 {
     $formsOtherThanQuantity = [];
     foreach ($forms as $key => $form) {
         if ('quantity' === $form->getName()) {
             $targetQuantity = $form->getData();
             $this->orderItemQuantityModifier->modify($data, $targetQuantity);
             continue;
         }
         $formsOtherThanQuantity[] = $form;
     }
     if (!empty($formsOtherThanQuantity)) {
         $this->propertyPathDataMapper->mapFormsToData($formsOtherThanQuantity, $data);
     }
 }
Exemplo n.º 4
0
 /**
  * @param array $configuration
  *
  * @return OrderItemInterface
  */
 protected function createItem(array $configuration)
 {
     $variant = $this->variantRepository->find($configuration['variant']);
     $promotionItem = $this->itemFactory->createNew();
     $promotionItem->setVariant($variant);
     $promotionItem->setUnitPrice((int) $configuration['price']);
     $this->orderItemQuantityModifier->modify($promotionItem, (int) $configuration['quantity']);
     return $promotionItem;
 }