示例#1
0
 /**
  * Creates a fake Order.
  *
  * @param BasketInterface $basket
  * @param Customer        $customer
  * @param array           $products
  * @param ObjectManager   $manager
  * @param int             $pos
  *
  * @return OrderInterface
  */
 protected function createOrder(BasketInterface $basket, Customer $customer, array $products, ObjectManager $manager, $pos)
 {
     $orderElements = array();
     $totalExcl = 0;
     $totalInc = 0;
     $order = new Order();
     // customer
     $order->setCustomer($customer);
     $order->setLocale($customer->getLocale());
     $order->setUsername($customer->getFullname());
     $order->setReference(sprintf('%02d%02d%02d%06d', 2013, 7, 1, $pos));
     // Billing
     $customerBillingAddressAddresses = $customer->getAddressesByType(BaseAddress::TYPE_BILLING);
     $customerBillingAddressAddresses = $customerBillingAddressAddresses->current();
     $order->setBillingAddress1($customerBillingAddressAddresses->getAddress1());
     $order->setBillingAddress2($customerBillingAddressAddresses->getAddress2());
     $order->setBillingAddress3($customerBillingAddressAddresses->getAddress3());
     $order->setBillingCity($customerBillingAddressAddresses->getCity());
     $order->setBillingCountryCode($customerBillingAddressAddresses->getCountryCode());
     $order->setBillingEmail($customer->getEmail());
     $order->setBillingName($customer->getFullname());
     $order->setBillingPhone($customerBillingAddressAddresses->getPhone());
     $order->setBillingFax($customer->getFaxNumber());
     $order->setBillingMobile($customer->getMobileNumber());
     $order->setBillingPostcode($customerBillingAddressAddresses->getPostcode());
     // Shipping
     $customerDeliveryAddressAddresses = $customer->getAddressesByType(BaseAddress::TYPE_DELIVERY);
     $customerDeliveryAddressAddresses = $customerDeliveryAddressAddresses->current();
     $order->setShippingAddress1($customerDeliveryAddressAddresses->getAddress1());
     $order->setShippingAddress2($customerDeliveryAddressAddresses->getAddress2());
     $order->setShippingAddress3($customerDeliveryAddressAddresses->getAddress3());
     $order->setShippingCity($customerDeliveryAddressAddresses->getCity());
     $order->setShippingCountryCode($customerDeliveryAddressAddresses->getCountryCode());
     $order->setShippingEmail($customer->getEmail());
     $order->setShippingName($customer->getFullname());
     $order->setShippingPhone($customerDeliveryAddressAddresses->getPhone());
     $order->setShippingFax($customer->getFaxNumber());
     $order->setShippingMobile($customer->getMobileNumber());
     $order->setShippingPostcode($customerDeliveryAddressAddresses->getPostcode());
     // Delivery
     $order->setDeliveryMethod('free');
     // @todo : change Delivery method integration
     $order->setDeliveryCost(rand(5, 40));
     $order->setDeliveryVat(20);
     $order->setDeliveryStatus(array_rand(Delivery::getStatusList()));
     $currency = new Currency();
     $currency->setLabel('EUR');
     // Payment
     $order->setCurrency($currency);
     $order->setPaymentMethod('free');
     // @todo : change Payment method integration
     $order->setPaymentStatus(array_rand(BaseTransaction::getStatusList()));
     // OrderElements
     foreach ($products as $product) {
         $orderElement = $this->createOrderElement($basket, $product);
         $orderElement->setOrder($order);
         $orderElements[] = $orderElement;
         $totalExcl += $orderElement->getUnitPrice(false);
         $totalInc += $orderElement->getUnitPrice(true);
     }
     $order->setOrderElements($orderElements);
     $order->setTotalExcl($totalExcl);
     $order->setTotalInc($totalInc);
     $order->setStatus(array_rand(BaseOrder::getStatusList()));
     if (OrderInterface::STATUS_VALIDATED == $order->getStatus()) {
         $order->setValidatedAt(new \DateTime());
     }
     $manager->persist($order);
     return $order;
 }
示例#2
0
 /**
  * Create and add deliveries for a given Product.
  *
  * @param ProductInterface $product
  * @param ObjectManager    $manager
  */
 protected function addProductDeliveries(ProductInterface $product, ObjectManager $manager)
 {
     $delivery = new Delivery();
     $delivery->setCountryCode('FR');
     $delivery->setCode('free');
     $delivery->setEnabled(true);
     $delivery->setPerItem(0);
     $delivery->setProduct($product);
     $product->addDelivery($delivery);
     $manager->persist($delivery);
     $delivery = new Delivery();
     $delivery->setCountryCode('GB');
     $delivery->setCode('free');
     $delivery->setEnabled(true);
     $delivery->setPerItem(0);
     $delivery->setProduct($product);
     $product->addDelivery($delivery);
     $manager->persist($delivery);
     $delivery = new Delivery();
     $delivery->setCountryCode('FR');
     $delivery->setCode('chronopost');
     $delivery->setEnabled(true);
     $delivery->setPerItem(rand(15, 30));
     $delivery->setProduct($product);
     $product->addDelivery($delivery);
     $manager->persist($delivery);
     $delivery = new Delivery();
     $delivery->setCountryCode('GB');
     $delivery->setCode('ups');
     $delivery->setEnabled(true);
     $delivery->setPerItem(rand(15, 30));
     $delivery->setProduct($product);
     $product->addDelivery($delivery);
     $manager->persist($delivery);
 }