/** * {@inheritdoc} */ protected function getPermissionForAttribute($class, $identifier, $attribute) { if ($this->object->isDefault()) { return self::ACCESS_DENIED; } return self::ACCESS_ABSTAIN; }
/** * @param ObjectManager $manager */ public function load(ObjectManager $manager) { $priceList = new PriceList(); $priceList->setDefault(true)->setCurrencies(['USD', 'EUR', 'CAD', 'AUD'])->setName('Default Price List'); $manager->persist($priceList); $manager->flush(); $this->addReference('default_price_list', $priceList); }
/** * @return string */ protected function getExportFile() { $result = $this->getContainer()->get('oro_importexport.handler.export')->handleExport('price_list_product_prices_export_to_csv', 'orob2b_pricing_product_price', ProcessorRegistry::TYPE_EXPORT, 'csv', null, ['price_list_id' => $this->priceList->getId()]); $result = json_decode($result->getContent(), true); $chains = explode('/', $result['url']); return $this->getContainer()->get('oro_importexport.file.file_system_operator')->getTemporaryFile(end($chains))->getRealPath(); }
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'); }
/** * @return ProductPrice */ public function getProductPrice() { $priceList = new PriceList(); $priceList->setCurrencies(['USD', 'EUR']); $productPrice = new ProductPrice(); $productPrice->setPriceList($priceList); return $productPrice; }
/** * {@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(); }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { $locator = $this->container->get('file_locator'); $filePath = $locator->locate('@OroB2BPricingBundle/Migrations/Data/Demo/ORM/data/price_lists.csv'); if (is_array($filePath)) { $filePath = current($filePath); } $handler = fopen($filePath, 'r'); $headers = fgetcsv($handler, 1000, ','); while (($data = fgetcsv($handler, 1000, ',')) !== false) { $row = array_combine($headers, array_values($data)); $currencies = array_map('trim', explode(',', $row['currencies'])); $priceList = new PriceList(); $priceList->setName($row['name'])->setDefault((bool) $row['default'])->setCurrencies($currencies); $manager->persist($priceList); } fclose($handler); $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); } }
/** * @param bool $isDefault * @return PriceList */ protected function getPriceList($isDefault) { $priceList = new PriceList(); $priceList->setDefault($isDefault); return $priceList; }
/** * @Route("/get-pricelist-currency-list/{id}", * name="orob2b_pricing_price_list_currency_list", * requirements={"id"="\d+"}) * @AclAncestor("orob2b_product_update") * * @param PriceList $priceList * @return JsonResponse */ public function getPriceListCurrencyList(PriceList $priceList) { $currencyNames = Intl::getCurrencyBundle()->getCurrencyNames($this->get('oro_locale.settings')->getLocale()); $currencies = array_intersect_key($currencyNames, array_fill_keys($priceList->getCurrencies(), null)); return new JsonResponse($currencies); }
/** * @return array */ public function submitProvider() { $priceList = new PriceList(); $priceList->setCurrencies(['GBP']); /** @var Product $expectedProduct */ $expectedProduct = $this->getProductEntityWithPrecision(2, 'kg', 3); $expectedPrice1 = (new Price())->setValue(42)->setCurrency('USD'); $expectedPrice2 = (new Price())->setValue(42)->setCurrency('GBP'); $expectedProductPrice = new ProductPrice(); $expectedProductPrice->setProduct($expectedProduct)->setQuantity(123)->setUnit($expectedProduct->getUnitPrecision('kg')->getUnit())->setPrice($expectedPrice1)->setPriceList($priceList); $expectedProductPrice2 = clone $expectedProductPrice; $expectedProductPrice2->setQuantity(123.556)->setPrice($expectedPrice2); $defaultProductPrice = new ProductPrice(); $defaultProductPrice->setPriceList($priceList); return ['product price without data' => ['defaultData' => $defaultProductPrice, 'submittedData' => [], 'expectedData' => clone $defaultProductPrice, 'rounding' => false], 'product price with data' => ['defaultData' => clone $defaultProductPrice, 'submittedData' => ['product' => 2, 'quantity' => 123, 'unit' => 'kg', 'price' => ['value' => 42, 'currency' => 'USD']], 'expectedData' => $expectedProductPrice, 'rounding' => true], 'product price with data for rounding' => ['defaultData' => clone $defaultProductPrice, 'submittedData' => ['product' => 2, 'quantity' => 123.5555, 'unit' => 'kg', 'price' => ['value' => 42, 'currency' => 'GBP']], 'expectedData' => $expectedProductPrice2, 'rounding' => true]]; }
/** * @param Product $product * @param ProductUnit $productUnit * @param float $quantity * @param string $currency * @param PriceList $priceList * @return Price */ protected function getPrice(Product $product, ProductUnit $productUnit, $quantity, $currency, PriceList $priceList) { $productUnitQuantity = new ProductUnitQuantity($product, $productUnit, $quantity); $identifier = $productUnitQuantity->getIdentifier(); if (!isset($this->prices[$priceList->getId()][$currency][$identifier])) { $prices = $this->productPriceProvider->getMatchedPrices([$productUnitQuantity], $currency, $priceList); $this->prices[$priceList->getId()][$currency][$identifier] = $prices[$identifier]; } $price = $this->prices[$priceList->getId()][$currency][$identifier]; return $price ?: Price::create(mt_rand(10, 1000), $currency); }