Author: Thomas Rabaix (thomas.rabaix@sonata-project.org)
Inheritance: implements Serializable, implements Sonata\Component\Basket\BasketInterface
Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $currency = new Currency();
     $currency->setLabel('EUR');
     $basket = new Basket();
     $basket->setCurrency($currency);
     $basket->setProductPool($this->getProductPool());
     $nbCustomers = 100;
     $products = array($this->getReference('php_plush_blue_goodie_product'), $this->getReference('php_plush_green_goodie_product'), $this->getReference('travel_japan_small_product'), $this->getReference('travel_japan_medium_product'), $this->getReference('travel_japan_large_product'), $this->getReference('travel_japan_extra_large_product'), $this->getReference('travel_quebec_small_product'), $this->getReference('travel_quebec_medium_product'), $this->getReference('travel_quebec_large_product'), $this->getReference('travel_quebec_extra_large_product'), $this->getReference('travel_paris_small_product'), $this->getReference('travel_paris_medium_product'), $this->getReference('travel_paris_large_product'), $this->getReference('travel_paris_extra_large_product'), $this->getReference('travel_switzerland_small_product'), $this->getReference('travel_switzerland_medium_product'), $this->getReference('travel_switzerland_large_product'), $this->getReference('travel_switzerland_extra_large_product'));
     for ($i = 1; $i <= $nbCustomers; $i++) {
         $customer = $this->generateCustomer($manager, $i);
         $customerProducts = array();
         $orderProductsKeys = array_rand($products, rand(1, count($products)));
         if (is_array($orderProductsKeys)) {
             foreach ($orderProductsKeys as $orderProductKey) {
                 $customerProducts[] = $products[$orderProductKey];
             }
         } else {
             $customerProducts = array($products[$orderProductsKeys]);
         }
         $order = $this->createOrder($basket, $customer, $customerProducts, $manager, $i);
         $this->createTransaction($order, $manager);
         $this->createInvoice($order, $manager);
         if (!($i % 10)) {
             $manager->flush();
         }
     }
     $manager->flush();
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function reset($full = true)
 {
     parent::reset($full);
     if ($full) {
         $this->basketElements = new ArrayCollection();
     }
 }
Exemplo n.º 3
0
 protected function getPreparedBasket()
 {
     $basket = new Basket();
     // create the provider mock
     $provider = $this->getMock('Sonata\\Component\\Product\\ProductProviderInterface');
     $provider->expects($this->any())->method('basketCalculatePrice')->will($this->returnValue(15));
     $provider->expects($this->any())->method('isAddableToBasket')->will($this->returnValue(true));
     // create the product manager mock
     $manager = $this->getMock('Sonata\\Component\\Product\\ProductManagerInterface');
     $manager->expects($this->any())->method('getClass')->will($this->returnValue('BasketTest_Product'));
     $definition = new ProductDefinition($provider, $manager);
     $pool = new Pool();
     $pool->addProduct('product_code', $definition);
     $basket->setProductPool($pool);
     return $basket;
 }
 /**
  * @return void
  */
 public function testOrder()
 {
     $basket = new Basket();
     $customer = $this->getMock('Sonata\\Component\\Customer\\CustomerInterface');
     $billingAddress = $this->getMock('Sonata\\Component\\Customer\\AddressInterface');
     $deliveryMethod = $this->getMock('Sonata\\Component\\Delivery\\ServiceDeliveryInterface');
     $deliveryMethod->expects($this->exactly(2))->method('isAddressRequired')->will($this->returnValue(true));
     $deliveryAddress = $this->getMock('Sonata\\Component\\Customer\\AddressInterface');
     $paymentMethod = $this->getMock('Sonata\\Component\\Payment\\PaymentInterface');
     $basket->setCustomer($customer);
     $basket->setBillingAddress($billingAddress);
     $basket->setDeliveryMethod($deliveryMethod);
     $basket->setDeliveryAddress($deliveryAddress);
     $basket->setPaymentMethod($paymentMethod);
     $currency = new Currency();
     $currency->setLabel('EUR');
     $basket->setCurrency($currency);
     $order = $this->getBasketTransform()->transformIntoOrder($basket);
     $this->assertInstanceOf('Sonata\\Component\\Order\\OrderInterface', $order, '::transformIntoOrder() returns an OrderInstance object');
 }