Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $now = new \DateTime();
     foreach ($this->data as $priceListData) {
         $priceList = new PriceList();
         $priceList->setName($priceListData['name'])->setDefault($priceListData['default'])->setCurrencies(['USD'])->setCreatedAt($now)->setUpdatedAt($now);
         foreach ($priceListData['customers'] as $customerReference) {
             /** @var Customer $customer */
             $customer = $this->getReference($customerReference);
             $priceList->addCustomer($customer);
         }
         foreach ($priceListData['groups'] as $customerGroupReference) {
             /** @var CustomerGroup $customerGroup */
             $customerGroup = $this->getReference($customerGroupReference);
             $priceList->addCustomerGroup($customerGroup);
         }
         foreach ($priceListData['websites'] as $websiteReference) {
             /** @var Website $website */
             $website = $this->getReference($websiteReference);
             $priceList->addWebsite($website);
         }
         foreach ($priceListData['currencies'] as $currencyCode) {
             $priceList->addCurrencyByCode($currencyCode);
         }
         $manager->persist($priceList);
         $this->setReference($priceListData['reference'], $priceList);
     }
     $manager->flush();
 }
 protected function prepareServices()
 {
     $this->form->expects($this->once())->method('setData')->with($this->entity);
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->request->setMethod('POST');
     $this->form->expects($this->once())->method('isValid')->willReturn(true);
     $this->manager->expects($this->at(0))->method('persist')->with($this->isType('object'));
     $repository = $this->getMockBuilder('OroB2B\\Bundle\\PricingBundle\\Entity\\Repository\\PriceListRepository')->disableOriginalConstructor()->getMock();
     $repository->expects($this->any())->method('setPriceListToCustomer')->will($this->returnCallback(function (Customer $customer, PriceList $priceList = null) {
         $this->entity->removeCustomer($customer);
         if ($priceList) {
             $this->entity->addCustomer($customer);
         }
     }));
     $repository->expects($this->any())->method('setPriceListToCustomerGroup')->will($this->returnCallback(function (CustomerGroup $customerGroup, PriceList $priceList = null) {
         $this->entity->removeCustomerGroup($customerGroup);
         if ($priceList) {
             $this->entity->addCustomerGroup($customerGroup);
         }
     }));
     $repository->expects($this->any())->method('setPriceListToWebsite')->will($this->returnCallback(function (Website $website, PriceList $priceList = null) {
         $this->entity->removeWebsite($website);
         if ($priceList) {
             $this->entity->addWebsite($website);
         }
     }));
     $this->manager->expects($this->any())->method('getRepository')->with($this->isType('string'))->willReturn($repository);
     $this->manager->expects($this->exactly(2))->method('flush');
 }
 /**
  * @param Customer $customer
  * @param PriceList $priceList
  */
 public function setPriceListToCustomer(Customer $customer, PriceList $priceList = null)
 {
     $oldPriceList = $this->getPriceListByCustomer($customer);
     if ($oldPriceList && $priceList && $oldPriceList->getId() === $priceList->getId()) {
         return;
     }
     if ($oldPriceList) {
         $oldPriceList->removeCustomer($customer);
     }
     if ($priceList) {
         $priceList->addCustomer($customer);
     }
 }