コード例 #1
0
 function it_does_not_save_addresses_for_guest_order(CustomerAddressAdderInterface $addressAdder, OrderInterface $order, CustomerInterface $customer)
 {
     $order->getCustomer()->willReturn($customer);
     $customer->getUser()->willReturn(null);
     $addressAdder->add($customer, Argument::any())->shouldNotBeCalled();
     $addressAdder->add($customer, Argument::any())->shouldNotBeCalled();
     $this->saveAddresses($order);
 }
コード例 #2
0
 /**
  * @param OrderInterface $order
  */
 public function saveAddresses(OrderInterface $order)
 {
     /** @var CustomerInterface $customer */
     $customer = $order->getCustomer();
     $shippingAddress = $order->getShippingAddress();
     $billingAddress = $order->getBillingAddress();
     $this->addressAdder->add($customer, clone $billingAddress);
     $this->addressAdder->add($customer, clone $shippingAddress);
 }
コード例 #3
0
 function it_saves_addresses_from_given_order(CustomerAddressAdderInterface $addressAdder, OrderInterface $order, CustomerInterface $customer, AddressInterface $shippingAddress, AddressInterface $billingAddress)
 {
     $order->getCustomer()->willReturn($customer);
     $order->getShippingAddress()->willReturn($shippingAddress);
     $order->getBillingAddress()->willReturn($billingAddress);
     $addressAdder->add($customer, clone $shippingAddress)->shouldBeCalled();
     $addressAdder->add($customer, clone $billingAddress)->shouldBeCalled();
     $this->saveAddresses($order);
 }
コード例 #4
0
 function it_returns_false_if_subject_coupon_is_eligible_to_promotion_and_number_of_usages_is_bigger_than_coupon_usage_limit(OrderRepositoryInterface $orderRepository, OrderInterface $subject, PromotionInterface $promotion, CouponInterface $coupon, CustomerInterface $customer)
 {
     $subject->getPromotionCoupon()->willReturn($coupon);
     $promotion->isCouponBased()->willReturn(true);
     $subject->getCustomer()->willReturn($customer);
     $coupon->getPromotion()->willReturn($promotion);
     $coupon->getPerCustomerUsageLimit()->willReturn(5);
     $orderRepository->countByCustomerAndCoupon($customer, $coupon)->willReturn(6);
     $this->isEligible($subject, $promotion)->shouldReturn(false);
 }
コード例 #5
0
 function it_dispatches_event_and_returns_false_if_subject_coupon_is_eligible_to_promotion_and_number_of_usages_is_bigger_than_coupon_usage_limit(CouponInterface $coupon, CustomerInterface $customer, EventDispatcherInterface $eventDispatcher, OrderInterface $subject, OrderRepositoryInterface $orderRepository, PromotionInterface $promotion)
 {
     $subject->getPromotionCoupon()->willReturn($coupon);
     $coupon->getPromotion()->willReturn($promotion);
     $subject->getCustomer()->willReturn($customer);
     $coupon->getPerCustomerUsageLimit()->willReturn(5);
     $orderRepository->countByCustomerAndCoupon($customer, $coupon)->willReturn(6);
     $eventDispatcher->dispatch(SyliusPromotionEvents::COUPON_NOT_ELIGIBLE, Argument::type(GenericEvent::class))->shouldBeCalled();
     $this->isEligible($subject, $promotion)->shouldReturn(false);
 }
コード例 #6
0
 function it_recalculates_prices_without_adding_anything_to_the_context_if_its_not_needed(DelegatingCalculatorInterface $priceCalculator, OrderInterface $order, OrderItemInterface $item, PriceableInterface $variant)
 {
     $order->getCustomer()->willReturn(null);
     $order->getChannel()->willReturn(null);
     $order->getItems()->willReturn([$item]);
     $item->isImmutable()->willReturn(false);
     $item->getQuantity()->willReturn(5);
     $item->getVariant()->willReturn($variant);
     $priceCalculator->calculate($variant, ['quantity' => 5])->willReturn(10);
     $item->setUnitPrice(10)->shouldBeCalled();
     $this->recalculate($order);
 }
コード例 #7
0
 function it_recalculates_prices_adding_customer_to_the_context(ChannelInterface $channel, CustomerGroupInterface $group, CustomerInterface $customer, OrderInterface $order, OrderItemInterface $item, ProductVariantInterface $variant, ProductVariantPriceCalculatorInterface $productVariantPriceCalculator)
 {
     $order->getCustomer()->willReturn($customer);
     $order->getChannel()->willReturn(null);
     $order->getItems()->willReturn([$item]);
     $order->getCurrencyCode()->willReturn(null);
     $customer->getGroup()->willReturn($group);
     $item->isImmutable()->willReturn(false);
     $item->getQuantity()->willReturn(5);
     $item->getVariant()->willReturn($variant);
     $order->getChannel()->willReturn($channel);
     $productVariantPriceCalculator->calculate($variant, ['channel' => $channel])->willReturn(10);
     $item->setUnitPrice(10)->shouldBeCalled();
     $this->process($order);
 }
コード例 #8
0
 /**
  * {@inheritdoc}
  */
 public function recalculate(OrderInterface $order)
 {
     $context = [];
     if (null !== ($customer = $order->getCustomer())) {
         $context['customer'] = $customer;
         $context['groups'] = $customer->getGroups()->toArray();
     }
     if (null !== $order->getChannel()) {
         $context['channel'] = [$order->getChannel()];
     }
     foreach ($order->getItems() as $item) {
         if ($item->isImmutable()) {
             continue;
         }
         $context['quantity'] = $item->getQuantity();
         $item->setUnitPrice($this->priceCalculator->calculate($item->getVariant(), $context));
     }
 }
 function it_returns_true_if_promotion_subject_has_no_customer(OrderInterface $promotionSubject, CorePromotionCouponInterface $promotionCoupon)
 {
     $promotionSubject->getCustomer()->willReturn(null);
     $promotionCoupon->getPerCustomerUsageLimit()->willReturn(42);
     $this->isEligible($promotionSubject, $promotionCoupon)->shouldReturn(true);
 }
コード例 #10
0
ファイル: OrderEmailManager.php プロジェクト: loic425/Sylius
 /**
  * @param OrderInterface $order
  */
 public function sendConfirmationEmail(OrderInterface $order)
 {
     $this->emailSender->send(Emails::ORDER_CONFIRMATION, [$order->getCustomer()->getEmail()], ['order' => $order]);
 }
コード例 #11
0
 function it_recognizes_subject_as_eligible_if_nth_order_is_equal_with_configured(CustomerInterface $customer, OrderInterface $subject, OrderRepositoryInterface $ordersRepository)
 {
     $subject->getCustomer()->willReturn($customer);
     $ordersRepository->countByCustomerAndPaymentState($customer, PaymentInterface::STATE_COMPLETED)->willReturn(9);
     $this->isEligible($subject, ['nth' => 10])->shouldReturn(true);
 }
コード例 #12
0
 public function it_recognizes_subject_as_eligible_if_customer_not_linked_to_order_and_coupon_not_restricted_by_customer(OrderInterface $subject, PromotionInterface $promotion, CouponInterface $coupon)
 {
     $subject->getCustomer()->willReturn(null);
     $coupon->getCode()->willReturn('D0003');
     $coupon->getPerCustomerUsageLimit()->willReturn(0);
     $coupon->getPromotion()->willReturn($promotion);
     $subject->getPromotionCoupons()->willReturn(array($coupon));
     $promotion->hasRules()->willReturn(false);
     $promotion->getStartsAt()->willReturn(null);
     $promotion->getEndsAt()->willReturn(null);
     $promotion->isCouponBased()->willReturn(true);
     $promotion->hasCoupons()->willReturn(true);
     $promotion->hasCoupon($coupon)->willReturn(true);
     $promotion->getUsageLimit()->willReturn(null);
     $promotion->getCoupons()->willReturn(array($coupon));
     $this->isEligible($subject, $promotion)->shouldReturn(true);
 }
コード例 #13
0
 function it_should_recognize_subject_as_not_eligible_if_customer_is_created_before_configured(OrderInterface $subject, TimestampableInterface $customer)
 {
     $subject->getCustomer()->willReturn($customer);
     $customer->getCreatedAt()->willReturn(new \DateTime());
     $this->isEligible($subject, ['time' => 30, 'unit' => 'days', 'after' => true])->shouldReturn(true);
 }
コード例 #14
0
ファイル: EmailContext.php プロジェクト: sylius/sylius
 /**
  * @Then /^an email with the summary of (order placed by "([^"]+)") should be sent to him$/
  */
 public function anEmailWithOrderConfirmationShouldBeSentTo(OrderInterface $order)
 {
     $this->assertEmailContainsMessageTo(sprintf('Your order no. %s has been successfully placed.', $order->getNumber()), $order->getCustomer()->getEmailCanonical());
 }
コード例 #15
0
 function it_recognizes_a_subject_as_not_eligible_if_it_is_first_order_of_new_customer_and_promotion_is_for_more_than_one_order(CustomerInterface $customer, OrderInterface $subject)
 {
     $subject->getCustomer()->willReturn($customer);
     $customer->getId()->willReturn(null);
     $this->isEligible($subject, ['nth' => 10])->shouldReturn(false);
 }
コード例 #16
0
ファイル: OrderController.php プロジェクト: okwinza/Sylius
 /**
  * @param OrderInterface $order
  *
  * @throws AccessDeniedException
  */
 protected function checkAccessToOrder(OrderInterface $order)
 {
     $customerGuestId = $this->get('session')->get('sylius_customer_guest_id');
     $customerGuest = null;
     if (null !== $customerGuestId) {
         $customerGuest = $this->get('sylius.repository.customer')->find($customerGuestId);
     }
     $loggedInCustomer = $this->getCustomer();
     $expectedCustomer = $order->getCustomer();
     if ($expectedCustomer !== $customerGuest && $expectedCustomer !== $loggedInCustomer) {
         throw $this->createAccessDeniedException();
     }
 }