public function testBuild() { $sku = 'TEST'; $qty = 3; $data = [ProductDataStorage::ENTITY_ITEMS_DATA_KEY => [[ProductDataStorage::PRODUCT_SKU_KEY => $sku, ProductDataStorage::PRODUCT_QUANTITY_KEY => $qty]]]; $request = new RFPRequest(); $productUnit = new ProductUnit(); $productUnit->setCode('item'); $product = $this->getProductEntity($sku, $productUnit); $this->assertMetadataCalled(); $this->assertRequestGetCalled(); $this->assertStorageCalled($data); $this->assertProductRepositoryCalled($product); /** @var \PHPUnit_Framework_MockObject_MockObject|FormBuilderInterface $builder */ $builder = $this->getMock('Symfony\\Component\\Form\\FormBuilderInterface'); $this->extension->buildForm($builder, ['data' => $request]); $this->assertCount(1, $request->getRequestProducts()); /** @var RequestProduct $requestProduct */ $requestProduct = $request->getRequestProducts()->first(); $this->assertEquals($product, $requestProduct->getProduct()); $this->assertEquals($product->getSku(), $requestProduct->getProductSku()); $this->assertCount(1, $requestProduct->getRequestProductItems()); /** @var RequestProductItem $requestProductItem */ $requestProductItem = $requestProduct->getRequestProductItems()->first(); $this->assertEquals($productUnit, $requestProductItem->getProductUnit()); $this->assertEquals($productUnit->getCode(), $requestProductItem->getProductUnitCode()); $this->assertEquals($qty, $requestProductItem->getQuantity()); }
/** * @param string $unitCode * @param integer $precision * * @return Product */ protected function getProductEntityWithPrecision($unitCode, $precision = 0) { $product = new Product(); $unit = new ProductUnit(); $unit->setCode($unitCode); $unitPrecision = (new ProductUnitPrecision())->setPrecision($precision)->setUnit($unit)->setProduct($product); return $product->addUnitPrecision($unitPrecision); }
/** * @param string $unitCode * @param float $quantity * @param bool $allowIncrements * @return QuoteProductOffer */ protected function createQuoteProductOffer($unitCode, $quantity, $allowIncrements) { $unit = new ProductUnit(); $unit->setCode($unitCode); $item = new QuoteProductOffer(); $item->setProductUnit($unit)->setQuantity($quantity)->setAllowIncrements($allowIncrements); return $item; }
/** * @param float|integer $value * @param ProductUnit $unit * @param boolean $isShort * @return string */ protected function formatData($value, ProductUnit $unit, $isShort = false) { if (!is_numeric($value)) { throw new \InvalidArgumentException(sprintf('The parameter "value" must be a numeric, but it is of type %s.', gettype($value))); } $translationKey = sprintf('orob2b.product_unit.%s.value.' . ($isShort ? 'short' : 'full'), $unit->getCode()); return $this->translator->transChoice($translationKey, $value, ['%count%' => $value]); }
public function testGetIdentifier() { $product = $this->getProduct(150); $productUnit = new ProductUnit(); $productUnit->setCode('kg'); $productUnitQuantity = new ProductUnitQuantity($product, $productUnit, 42); $this->assertEquals('150-kg-42', $productUnitQuantity->getIdentifier()); }
/** * @param array $parameters * @return ProductUnitPrecision */ protected function createPrecision(array $parameters) { $unit = new ProductUnit(); $unit->setCode($parameters['unit']); $precision = new ProductUnitPrecision(); $precision->setUnit($unit)->setPrecision($parameters['precision']); return $precision; }
/** * @param ObjectManager $manager * @param string $code * @param int $precision * @return ProductUnit */ protected function createProductUnit(ObjectManager $manager, $code, $precision) { $productUnit = new ProductUnit(); $productUnit->setCode($code); $productUnit->setDefaultPrecision($precision); $manager->persist($productUnit); $this->addReference('product_unit.' . $code, $productUnit); return $productUnit; }
/** * @param integer $productId * @param string $unitCode * @param integer $precision * * @return Product */ protected function getProductEntityWithPrecision($productId, $unitCode, $precision = 0) { /** @var Product $product */ $product = $this->getEntity('OroB2B\\Bundle\\ProductBundle\\Entity\\Product', $productId); $unit = new ProductUnit(); $unit->setCode($unitCode); $unitPrecision = new ProductUnitPrecision(); $unitPrecision->setPrecision($precision)->setUnit($unit)->setProduct($product); return $product->addUnitPrecision($unitPrecision); }
public function testGetAvailableUnitCodes() { $unit = new ProductUnit(); $unit->setCode('kg')->setDefaultPrecision(3); $unitPrecision = new ProductUnitPrecision(); $unitPrecision->setUnit($unit)->setPrecision($unit->getDefaultPrecision()); $product = new Product(); $product->addUnitPrecision($unitPrecision); $this->assertEquals(['kg'], $product->getAvailableUnitCodes()); }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { foreach ($this->productUnits as $item) { $productUnit = new ProductUnit(); $productUnit->setCode($item['code'])->setDefaultPrecision($item['defaultPrecision']); $manager->persist($productUnit); } if (!empty($this->productUnits)) { $manager->flush(); $manager->clear(); } }
/** * @param Product $product * @param ProductUnit $productUnit * @param float $quantity */ public function __construct(Product $product, ProductUnit $productUnit, $quantity) { if (!$product->getId()) { throw new \InvalidArgumentException('Product must have id.'); } $this->product = $product; if (!$productUnit->getCode()) { throw new \InvalidArgumentException('ProductUnit must have code.'); } $this->productUnit = $productUnit; if (!is_numeric($quantity) || $quantity < 0) { throw new \InvalidArgumentException('Quantity must be numeric and more than or equal zero.'); } $this->quantity = $quantity; }
/** * @return array * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function finishViewProvider() { $precision = new ProductUnitPrecision(); $unit = new ProductUnit(); $unit->setCode('code'); $precision->setUnit($unit); return ['empty item' => ['inputData' => ['options' => [], 'productUnitHolder' => null], 'expectedData' => ['empty_value' => null, 'choices' => null]], 'without parent form' => ['inputData' => ['options' => [], 'productHolder' => $this->createProductUnitHolder(1, 'sku', new ProductUnit(), $this->createProductHolder(1, 'sku', null))], 'expectedData' => ['empty_value' => null, 'choices' => null], false], 'filled item' => ['inputData' => ['options' => [], 'productUnitHolder' => $this->createProductUnitHolder(1, 'sku', new ProductUnit(), $this->createProductHolder(1, 'sku', null))], 'expectedData' => ['empty_value' => null, 'choices' => []]], 'existing product' => ['inputData' => ['options' => [], 'productUnitHolder' => $this->createProductUnitHolder(1, 'sku', new ProductUnit(), $this->createProductHolder(1, 'sku', (new Product())->addUnitPrecision($precision)))], 'expectedData' => ['empty_value' => 'orob2b.product.productunit.removed:sku', 'choices' => ['code' => 'orob2b.product_unit.code.label.full']]], 'existing product and compact mode' => ['inputData' => ['options' => ['compact' => true], 'productUnitHolder' => $this->createProductUnitHolder(1, 'sku', new ProductUnit(), $this->createProductHolder(1, 'sku', (new Product())->addUnitPrecision($precision)))], 'expectedData' => ['empty_value' => 'orob2b.product.productunit.removed:sku', 'choices' => ['code' => 'orob2b.product_unit.code.label.short']]], 'deleted product' => ['inputData' => ['options' => [], 'productUnitHolder' => $this->createProductUnitHolder(1, 'sku', null, $this->createProductHolder(1, 'sku', null))], 'expectedData' => ['empty_value' => 'orob2b.product.productunit.removed:sku', 'choices' => []]]]; }
/** * @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; }
/** * @param boolean $withProductUnitPrecision * @return Product */ protected function createExpectedProductEntity($withProductUnitPrecision = false) { $expectedProduct = new StubProduct(); $productUnit = new ProductUnit(); $productUnit->setCode('kg'); if ($withProductUnitPrecision) { $productUnitPrecision = new ProductUnitPrecision(); $productUnitPrecision->setProduct($expectedProduct)->setUnit($productUnit)->setPrecision(3); $expectedProduct->addUnitPrecision($productUnitPrecision); } return $expectedProduct->setSku('test sku'); }
/** * @return array */ protected function prepareChoices() { $choices = []; foreach ($this->units as $unitCode) { $unit = new ProductUnit(); $unit->setCode($unitCode); $choices[$unitCode] = $unit; } return $choices; }
/** * @param float $quantity * @return ProductUnitQuantity */ protected function getProductUnitQuantity($quantity) { /** @var Product $product */ $product = $this->getEntity('OroB2B\\Bundle\\ProductBundle\\Entity\\Product', 42); $productUnit = new ProductUnit(); $productUnit->setCode('kg'); return new ProductUnitQuantity($product, $productUnit, $quantity); }
/** * @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; }
/** * @return ProductUnit */ protected function createProductUnit() { $productUnit = new ProductUnit(); $productUnit->setCode('kg'); return $productUnit; }
/** * Set productUnit * * @param ProductUnit $productUnit * @return $this */ public function setProductUnit(ProductUnit $productUnit = null) { $this->productUnit = $productUnit; if ($productUnit) { $this->productUnitCode = $productUnit->getCode(); } return $this; }
/** * Set productUnit * * @param ProductUnit $productUnit * @return $this */ public function setProductUnit(ProductUnit $productUnit = null) { if ($productUnit && (!$this->productUnit || $productUnit->getCode() !== $this->productUnit->getCode())) { $this->requirePriceRecalculation = true; } $this->productUnit = $productUnit; return $this; }
/** * @param string $unitCode * @param float $quantity * @param float $priceValue * @param string $priceCurrency * @param int $priceType * @return QuoteProductOffer */ protected function createQuoteProductOffer($unitCode, $quantity, $priceType, $priceValue, $priceCurrency) { $unit = new ProductUnit(); $unit->setCode($unitCode); $price = Price::create($priceValue, $priceCurrency); $quoteProductOffer = new QuoteProductOffer(); $quoteProductOffer->setProductUnit($unit)->setQuantity($quantity)->setPrice($price)->setPriceType($priceType); return $quoteProductOffer; }
/** * @param boolean $withProductUnitPrecision * @param boolean $withNamesAndDescriptions * @return Product */ protected function createExpectedProductEntity($withProductUnitPrecision = false, $withNamesAndDescriptions = false) { $expectedProduct = new StubProduct(); $productUnit = new ProductUnit(); $productUnit->setCode('kg'); if ($withProductUnitPrecision) { $productUnitPrecision = new ProductUnitPrecision(); $productUnitPrecision->setProduct($expectedProduct)->setUnit($productUnit)->setPrecision(3); $expectedProduct->addUnitPrecision($productUnitPrecision); } if ($withNamesAndDescriptions) { $expectedProduct->addName($this->createLocalizedValue('first name'))->addName($this->createLocalizedValue('second name'))->addDescription($this->createLocalizedValue(null, 'first description'))->addDescription($this->createLocalizedValue(null, 'second description')); } return $expectedProduct->setSku('test sku'); }