/** * @return Price */ protected function createPrice() { $price = new Price(); $price->setValue(100); $price->setCurrency('USD'); return $price; }
public function testValidateWithNotAllowedCurrency() { $invalidCurrency = 'ABC'; $price = new Price(); $price->setValue('50')->setCurrency($invalidCurrency); $productPrice = $this->getProductPrice(); $productPrice->setPrice($price); $this->context->expects($this->once())->method('addViolationAt')->with('price.currency', $this->constraint->message, $this->equalTo(['%invalidCurrency%' => $invalidCurrency])); $this->validator->validate($productPrice, $this->constraint); }
/** * @param int $productId * @param string $unitCode * @param int $quantity * @param float $value * @param string $currency * @return ProductPrice */ protected function createPrice($productId, $unitCode, $quantity, $value, $currency) { $productPrice = new ProductPrice(); $price = new Price(); $price->setCurrency($currency); $price->setValue($value); $product = new Product(); $idReflection = new \ReflectionProperty(get_class($product), 'id'); $idReflection->setAccessible(true); $idReflection->setValue($product, $productId); $unit = new ProductUnit(); $unit->setCode($unitCode); $productPrice->setProduct($product); $productPrice->setUnit($unit); $productPrice->setQuantity($quantity); $productPrice->setPrice($price); return $productPrice; }
public function testPrice() { $value = 1.1; $currency = 'USD'; $price = new Price(); $price->setCurrency($currency); $price->setValue($value); $item = new BaseQuoteProductItem(); $item->setPrice($price); static::assertSame($price, $item->getPrice()); $item->postLoad(); static::assertNotSame($price, $item->getPrice()); static::assertEquals($price, $item->getPrice()); $item->updatePrice(); $reflection = new \ReflectionProperty(get_class($item), 'value'); $reflection->setAccessible(true); static::assertEquals($value, $reflection->getValue($item)); $reflection = new \ReflectionProperty(get_class($item), 'currency'); $reflection->setAccessible(true); static::assertEquals($currency, $reflection->getValue($item)); }
public function testGetAvailableCurrencies() { $this->assertEquals(['EUR' => 'EUR', 'USD' => 'USD'], $this->repository->getAvailableCurrencies()); $em = $this->getContainer()->get('doctrine')->getManager(); $price = new Price(); $price->setValue(1); $price->setCurrency('UAH'); /** @var Product $product */ $product = $this->getReference('product.1'); /** @var ProductUnit $unit */ $unit = $this->getReference('product_unit.liter'); /** @var PriceList $priceList */ $priceList = $this->getReference('price_list_1'); $productPrice = new ProductPrice(); $productPrice->setPrice($price)->setProduct($product)->setQuantity(1)->setUnit($unit)->setPriceList($priceList); $em->persist($productPrice); $em->flush(); $this->assertEquals(['EUR' => 'EUR', 'UAH' => 'UAH', 'USD' => 'USD'], $this->repository->getAvailableCurrencies()); }
/** * @param integer $priceListId * @param integer $quantity * @param string $unitCode * @param string $currency * @return ProductPrice */ protected function createPriceList($priceListId, $quantity, $unitCode, $currency) { $unit = new ProductUnit(); $unit->setCode($unitCode); $price = new Price(); $price->setValue(100)->setCurrency($currency); $productPrice = new ProductPrice(); $productPrice->setProduct($this->getEntity('OroB2B\\Bundle\\ProductBundle\\Entity\\Product', 42))->setPriceList($this->getEntity('OroB2B\\Bundle\\PricingBundle\\Entity\\PriceList', $priceListId))->setQuantity($quantity)->setUnit($unit)->setPrice($price); return $productPrice; }
/** * @return ProductPrice */ public function getProductPrice() { $unit = new ProductUnit(); $unit->setCode('kg'); $unitPrecision = new ProductUnitPrecision(); $unitPrecision->setUnit($unit)->setPrecision(3); $product = new Product(); $product->setSku('testSku')->addUnitPrecision($unitPrecision); $price = new Price(); $price->setValue('50')->setCurrency('USD'); $productPrice = new ProductPrice(); $productPrice->setPriceList(new PriceList())->setProduct($product)->setQuantity('10')->setPrice($price); return $productPrice; }