/** * {@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(); }
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; }