/**
  * {@inheritdoc}
  *
  * @param Price $price
  * @param Constraint $constraint
  */
 public function validate($price, Constraint $constraint)
 {
     if ($price->getValue() && !$price->getCurrency()) {
         /* @var $constraint Constraints\OptionalPrice */
         $this->context->addViolationAt('currency', $constraint->message);
     }
 }
 public function testUpdatePrice()
 {
     $item = new RequestProductItem();
     $item->setPrice(Price::create(11, 'EUR'));
     $item->updatePrice();
     $this->assertEquals(11, $this->getProperty($item, 'value'));
     $this->assertEquals('EUR', $this->getProperty($item, 'currency'));
 }
 public function testSetPrice()
 {
     $price = Price::create(22, 'EUR');
     $item = new QuoteProductRequest();
     $item->setPrice($price);
     $this->assertEquals($price, $item->getPrice());
     $this->assertEquals(22, $this->getProperty($item, 'value'));
     $this->assertEquals('EUR', $this->getProperty($item, 'currency'));
 }
 /**
  * @return array
  */
 public function processValidDataProvider()
 {
     $productUnit = (new ProductUnit())->setCode('item1');
     $product = new Product();
     $requestProductItem = (new RequestProductItem())->setQuantity(10)->setPrice(OptionalPrice::create(20, 'USD'))->setProductUnit($productUnit);
     $requestProduct = (new RequestProduct())->setProduct($product)->setComment('comment1')->addRequestProductItem($requestProductItem);
     $request = (new Request())->addRequestProduct($requestProduct);
     $quoteProductRequest = (new QuoteProductRequest())->setQuantity(10)->setPrice(OptionalPrice::create(20, 'USD'))->setProductUnit($productUnit)->setRequestProductItem($requestProductItem);
     $quoteProduct = (new QuoteProduct())->setProduct($product)->setCommentCustomer('comment1')->setType(QuoteProduct::TYPE_REQUESTED)->addQuoteProductRequest($quoteProductRequest);
     $quote = (new Quote())->setRequest($request)->setOwner($this->getUser())->addQuoteProduct($quoteProduct);
     return ['empty request' => ['input' => new Request(), 'expected' => (new Quote())->setRequest(new Request())->setOwner($this->getUser())], 'filled request' => ['input' => $request, 'expected' => $quote]];
 }
 /**
  * @return array
  */
 public function processValidDataProvider()
 {
     $productUnit = (new ProductUnit())->setCode('item1');
     $product = new Product();
     $accountUser = new AccountUser();
     $account = new Account();
     $requestProductItem = (new RequestProductItem())->setQuantity(10)->setPrice(OptionalPrice::create(20, 'USD'))->setProductUnit($productUnit);
     $requestProduct = (new RequestProduct())->setProduct($product)->setComment('comment1')->addRequestProductItem($requestProductItem);
     $request = (new Request())->setAccount($account)->setAccountUser($accountUser)->addRequestProduct($requestProduct);
     $quoteProductRequest = (new QuoteProductRequest())->setQuantity(10)->setPrice(OptionalPrice::create(20, 'USD'))->setProductUnit($productUnit)->setRequestProductItem($requestProductItem);
     $quoteProductOffer = (new QuoteProductOffer())->setQuantity(10)->setProductUnit($productUnit)->setPriceType(QuoteProductOffer::PRICE_TYPE_UNIT)->setAllowIncrements(true);
     $quoteProduct = (new QuoteProduct())->setProduct($product)->setCommentAccount('comment1')->setType(QuoteProduct::TYPE_REQUESTED)->addQuoteProductRequest($quoteProductRequest)->addQuoteProductOffer($quoteProductOffer);
     $quote = (new Quote())->setAccount($account)->setAccountUser($accountUser)->setRequest($request)->setOwner($this->getUser())->addQuoteProduct($quoteProduct)->setOrganization($this->getUser()->getOrganization());
     return ['empty request' => ['input' => new Request(), 'expected' => (new Quote())->setRequest(new Request())->setOwner($this->getUser())->setOrganization($this->getUser()->getOrganization())], 'filled request' => ['input' => $request, 'expected' => $quote]];
 }
 /**
  * @return array
  */
 public function formatRequestProvider()
 {
     return ['existing product unit' => ['inputData' => ['item' => new QuoteProductRequest(), 'quantity' => 15, 'unitCode' => 'kg', 'price' => OptionalPrice::create(10, 'USD'), 'unit' => (new ProductUnit())->setCode('kg')], 'expectedData' => ['formatPrice' => true, 'formatUnitValue' => true, 'formatUnitLabel' => true, 'formattedUnits' => '15 kilogram', 'formattedPrice' => '10.00 USD', 'formattedUnit' => 'kilogram', 'formattedString' => 'orob2b.sale.quoteproductrequest.item']], 'empty price' => ['inputData' => ['item' => new QuoteProductRequest(), 'quantity' => 15, 'unitCode' => 'kg', 'price' => null, 'unit' => (new ProductUnit())->setCode('kg')], 'expectedData' => ['formatPrice' => false, 'formatUnitValue' => true, 'formatUnitLabel' => true, 'formattedUnits' => '15 kilogram', 'formattedPrice' => 'N/A', 'formattedUnit' => 'kilogram', 'formattedString' => 'orob2b.sale.quoteproductrequest.item']], 'empty quantity' => ['inputData' => ['item' => new QuoteProductRequest(), 'quantity' => null, 'unitCode' => 'kg', 'price' => OptionalPrice::create(10, 'USD'), 'unit' => (new ProductUnit())->setCode('kg')], 'expectedData' => ['formatPrice' => true, 'formatUnitValue' => false, 'formatUnitLabel' => true, 'formattedUnits' => 'N/A', 'formattedPrice' => '10.00 USD', 'formattedUnit' => 'kilogram', 'formattedString' => 'orob2b.sale.quoteproductrequest.item']], 'empty quantity and price' => ['inputData' => ['item' => new QuoteProductRequest(), 'quantity' => null, 'unitCode' => 'kg', 'price' => null, 'unit' => (new ProductUnit())->setCode('kg')], 'expectedData' => ['formatPrice' => false, 'formatUnitValue' => false, 'formatUnitLabel' => false, 'formattedUnits' => 'N/A', 'formattedPrice' => 'N/A', 'formattedUnit' => 'kilogram', 'formattedString' => 'N/A']], 'deleted product unit' => ['inputData' => ['item' => new QuoteProductRequest(), 'quantity' => 25, 'unitCode' => 'item', 'price' => OptionalPrice::create(20, 'EUR'), 'unit' => null], 'expectedData' => ['formatPrice' => true, 'formatUnitValue' => false, 'formatUnitLabel' => true, 'formattedUnits' => '25 item', 'formattedPrice' => '20.00 EUR', 'formattedUnit' => 'item', 'formattedString' => 'orob2b.sale.quoteproductrequest.item']]];
 }
 /**
  * @param Request $request
  * @param ObjectManager $manager
  */
 protected function processRequestProducts(Request $request, ObjectManager $manager)
 {
     $products = $this->getProducts($manager);
     $currencies = $this->getCurrencies();
     for ($i = 0; $i < rand(1, 10); $i++) {
         $product = $products[rand(0, count($products) - 1)];
         $unitPrecisions = $product->getUnitPrecisions();
         if (!count($unitPrecisions)) {
             continue;
         }
         $requestProduct = new RequestProduct();
         $requestProduct->setProduct($product);
         $requestProduct->setComment(sprintf('Notes %s', $i));
         for ($j = 0; $j < rand(1, 10); $j++) {
             $productUnit = $unitPrecisions[rand(0, count($unitPrecisions) - 1)]->getUnit();
             $currency = $currencies[rand(0, count($currencies) - 1)];
             $requestProductItem = new RequestProductItem();
             $requestProductItem->setPrice(Price::create(rand(1, 100), $currency))->setQuantity(rand(1, 100))->setProductUnit($productUnit);
             $requestProduct->addRequestProductItem($requestProductItem);
         }
         $request->addRequestProduct($requestProduct);
     }
 }
 /**
  * @param float $value
  * @param string $currency
  * @return OptionalPrice
  */
 protected function createPrice($value, $currency)
 {
     return OptionalPrice::create($value, $currency);
 }
Exemplo n.º 9
0
 /**
  * @ORM\PrePersist
  * @ORM\PreUpdate
  */
 public function updatePrice()
 {
     $this->value = $this->price ? $this->price->getValue() : null;
     $this->currency = $this->price ? $this->price->getCurrency() : null;
 }
 /**
  * @return array
  */
 public function validateProvider()
 {
     return ['empty data' => ['isValid' => true, 'inputData' => Price::create(null, null)], 'empty value' => ['isValid' => true, 'inputData' => Price::create(null, 'USD')], 'empty currency' => ['isValid' => false, 'inputData' => Price::create(11, null)], 'valid value' => ['isValid' => true, 'inputData' => Price::create(11, 'USD')]];
 }
Exemplo n.º 11
0
 /**
  * @ORM\PostLoad
  */
 public function postLoad()
 {
     if (null !== $this->value && null !== $this->currency) {
         $this->price = OptionalPrice::create($this->value, $this->currency);
     }
 }
 /**
  * @return array
  */
 public function submitProvider()
 {
     return ['valid data' => ['isValid' => true, 'submittedData' => ['value' => 10, 'currency' => 'USD'], 'expectedData' => OptionalPrice::create(10, 'USD'), 'defaultData' => new OptionalPrice()], 'empty value & currency' => ['isValid' => true, 'submittedData' => [], 'expectedData' => null, 'defaultData' => new OptionalPrice()], 'empty value' => ['isValid' => true, 'submittedData' => ['currency' => 'USD'], 'expectedData' => null, 'defaultData' => new OptionalPrice()], 'empty currency' => ['isValid' => false, 'submittedData' => ['value' => 10.0], 'expectedData' => OptionalPrice::create(10.0, null), 'defaultData' => new OptionalPrice()]];
 }
Exemplo n.º 13
0
 /**
  * @param float $price
  * @param string $currency
  * @param OptionalPrice $expected
  * @dataProvider createProvider
  */
 public function testCreate($price, $currency, $expected)
 {
     $price = OptionalPrice::create($price, $currency);
     $this->assertInstanceOf('Oro\\Bundle\\CurrencyBundle\\Model\\OptionalPrice', $price);
     $this->assertEquals($expected, $price);
 }