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('setPriceListToAccount')->will($this->returnCallback(function (Account $account, PriceList $priceList = null) {
         $this->entity->removeAccount($account);
         if ($priceList) {
             $this->entity->addAccount($account);
         }
     }));
     $repository->expects($this->any())->method('setPriceListToAccountGroup')->will($this->returnCallback(function (AccountGroup $accountGroup, PriceList $priceList = null) {
         $this->entity->removeAccountGroup($accountGroup);
         if ($priceList) {
             $this->entity->addAccountGroup($accountGroup);
         }
     }));
     $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');
 }
예제 #2
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();
 }
 /**
  * @param Website $website
  * @param PriceList $priceList
  */
 public function setPriceListToWebsite(Website $website, PriceList $priceList = null)
 {
     $oldPriceList = $this->getPriceListByWebsite($website);
     if ($oldPriceList && $priceList && $oldPriceList->getId() === $priceList->getId()) {
         return;
     }
     if ($oldPriceList) {
         $oldPriceList->removeWebsite($website);
     }
     if ($priceList) {
         $priceList->addWebsite($website);
     }
 }