/**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     /** @var EntityManager $manager */
     $user = $this->getUser($manager);
     $businessUnit = $user->getOwner();
     $organization = $user->getOrganization();
     $locator = $this->container->get('file_locator');
     $filePath = $locator->locate('@OroB2BProductBundle/Migrations/Data/Demo/ORM/data/products.csv');
     if (is_array($filePath)) {
         $filePath = current($filePath);
     }
     $handler = fopen($filePath, 'r');
     $headers = fgetcsv($handler, 1000, ',');
     $inventoryStatuses = $this->getAllEnumValuesByCode($manager, 'prod_inventory_status');
     $visibilities = $this->getAllEnumValuesByCode($manager, 'prod_visibility');
     $statuses = $this->getAllEnumValuesByCode($manager, 'prod_status');
     while (($data = fgetcsv($handler, 1000, ',')) !== false) {
         $row = array_combine($headers, array_values($data));
         $product = new Product();
         $product->setOwner($businessUnit)->setOrganization($organization)->setSku($row['productCode'])->setInventoryStatus($inventoryStatuses[array_rand($inventoryStatuses)])->setVisibility($visibilities[array_rand($visibilities)])->setStatus($statuses[array_rand($statuses)]);
         $manager->persist($product);
     }
     fclose($handler);
     $manager->flush();
 }
 /**
  * @param Product   $product
  * @param string    $unitCode
  * @param float|int $quantity
  *
  * @return float|int Rounded quantity
  */
 public function roundProductQuantity(Product $product, $unitCode, $quantity)
 {
     $unitPrecision = $product->getUnitPrecision($unitCode);
     if ($unitPrecision) {
         $quantity = $this->roundingService->round($quantity, $unitPrecision->getPrecision());
     }
     return $quantity;
 }
 public function testGetProductSku()
 {
     $product = new Product();
     $product->setSku('test');
     $price = new ProductPrice();
     $price->setProduct($product);
     $this->assertEquals($product->getSku(), $price->getProductSku());
 }
 /**
  * @param string $sku
  * @param ProductUnit|null $productUnit
  * @return Product
  */
 protected function getProductEntity($sku, ProductUnit $productUnit = null)
 {
     $product = new Product();
     $product->setSku($sku);
     if ($productUnit) {
         $productUnitPrecision = new ProductUnitPrecision();
         $productUnitPrecision->setUnit($productUnit);
         $product->addUnitPrecision($productUnitPrecision);
     }
     return $product;
 }
 public function testEvent()
 {
     $product = new Product();
     $product->setSku('SKU-1');
     $sourceProduct = new Product();
     $sourceProduct->setSku('SKU-2');
     /** @var AbstractProductDuplicateEvent $event */
     $event = $this->getMockBuilder('OroB2B\\Bundle\\ProductBundle\\Event\\AbstractProductDuplicateEvent')->setConstructorArgs([$product, $sourceProduct])->getMockForAbstractClass();
     $this->assertEquals($product, $event->getProduct());
     $this->assertEquals($sourceProduct, $event->getSourceProduct());
 }
 /**
  * @param Product $product
  * @param string $unitCode
  * @return int|null
  */
 protected function getPrecision(Product $product, $unitCode)
 {
     $precision = null;
     $productUnitPrecisions = $product->getUnitPrecisions();
     foreach ($productUnitPrecisions as $productUnitPrecision) {
         if ($productUnitPrecision->getUnit() && $productUnitPrecision->getUnit()->getCode() === $unitCode) {
             $precision = $productUnitPrecision->getPrecision();
         }
     }
     return $precision;
 }
示例#7
0
 /**
  * @param ObjectManager $manager
  * @param string $sku
  * @return Product
  */
 protected function createProduct(ObjectManager $manager, $sku)
 {
     $businessUnit = $manager->getRepository('OroOrganizationBundle:BusinessUnit')->getFirst();
     $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst();
     $product = new Product();
     $product->setSku($sku);
     $product->setOwner($businessUnit);
     $product->setOrganization($organization);
     $manager->persist($product);
     $this->addReference($sku, $product);
     return $product;
 }
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     /** @var EntityManager $manager */
     $user = $this->getUser($manager);
     $businessUnit = $user->getOwner();
     $organization = $user->getOrganization();
     foreach ($this->products as $item) {
         $product = new Product();
         $product->setOwner($businessUnit)->setOrganization($organization)->setSku($item['productCode']);
         $manager->persist($product);
     }
     $manager->flush();
 }
 /**
  * @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;
 }
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     /** @var EntityManager $manager */
     $user = $this->getUser($manager);
     $businessUnit = $user->getOwner();
     $organization = $user->getOrganization();
     foreach ($this->products as $item) {
         $product = new Product();
         $product->setOwner($businessUnit)->setOrganization($organization)->setSku($item['productCode']);
         $name = new LocalizedFallbackValue();
         $product->addName($name);
         $name->setString($item['productCode']);
         $manager->persist($product);
         $this->addReference($item['productCode'], $product);
     }
     $manager->flush();
 }
 /**
  * @param int $id
  * @param array|ProductUnit[] $productUnits
  * @param string $unitCode
  * @return \PHPUnit_Framework_MockObject_MockObject|RequestProductItem
  */
 protected function createRequestProductItem($id, array $productUnits = [], $unitCode = null)
 {
     $productUnit = null;
     $product = new Product();
     foreach ($productUnits as $unit) {
         $product->addUnitPrecision((new ProductUnitPrecision())->setUnit($unit));
         if ($unitCode && $unit->getCode() == $unitCode) {
             $productUnit = $unit;
         }
     }
     /* @var $item \PHPUnit_Framework_MockObject_MockObject|RequestProductItem */
     $item = $this->getMock('OroB2B\\Bundle\\RFPBundle\\Entity\\RequestProductItem');
     $item->expects($this->any())->method('getId')->will($this->returnValue($id));
     $item->expects($this->any())->method('getRequestProduct')->will($this->returnValue((new RequestProduct())->setProduct($product)));
     $item->expects($this->any())->method('getProductUnit')->will($this->returnValue($productUnit));
     $item->expects($this->any())->method('getProductUnitCode')->will($this->returnValue($unitCode));
     return $item;
 }
 /**
  * @param array $offers
  * @param array $productParams
  * @param array $suggestedProductParams
  * @return QuoteProduct
  */
 protected function createQuoteProduct(array $offers, array $productParams = [], array $suggestedProductParams = [])
 {
     $quoteProduct = new QuoteProduct();
     foreach ($offers as $offer) {
         $quoteProduct->addQuoteProductOffer($offer);
     }
     if ($productParams) {
         $product = new Product();
         $product->addUnitPrecision($this->createPrecision($productParams));
         $quoteProduct->setProduct($product);
     }
     if ($suggestedProductParams) {
         $suggestedProduct = new Product();
         $suggestedProduct->addUnitPrecision($this->createPrecision($suggestedProductParams));
         $quoteProduct->setProductReplacement($suggestedProduct);
     }
     return $quoteProduct;
 }
示例#13
0
 public function testClone()
 {
     $id = 123;
     $product = new Product();
     $product->getUnitPrecisions()->add(new ProductUnitPrecision());
     $refProduct = new \ReflectionObject($product);
     $refId = $refProduct->getProperty('id');
     $refId->setAccessible(true);
     $refId->setValue($product, $id);
     $this->assertEquals($id, $product->getId());
     $this->assertCount(1, $product->getUnitPrecisions());
     $productCopy = clone $product;
     $this->assertNull($productCopy->getId());
     $this->assertCount(0, $productCopy->getUnitPrecisions());
 }
 public function testProcessLoadPriceAndProduct()
 {
     $productPrice = new ProductPrice();
     $productPrice->setQuantity(555);
     $this->setValue($productPrice, 'value', 1.2);
     $this->setValue($productPrice, 'currency', 'USD');
     /** @var ProductUnit $unit */
     $unit = $this->getReference('product_unit.liter');
     /** @var Product $product */
     $product = $this->getReference('product.1');
     /** @var PriceList $priceList */
     $priceList = $this->getReference('price_list_1');
     $productObject = new Product();
     $productObject->setSku($product->getSku());
     $productPrice->setProduct($product);
     $productPrice->setUnit($unit);
     $productPrice->setPriceList($priceList);
     $this->strategy->process($productPrice);
     $this->assertNotEmpty($productPrice->getPrice());
     $this->assertEquals('USD', $productPrice->getPrice()->getCurrency());
     $this->assertEquals(1.2, $productPrice->getPrice()->getValue());
     $this->assertNotEmpty($productPrice->getProduct());
     $this->assertEquals($product->getSku(), $productPrice->getProduct()->getSku());
 }
示例#15
0
 /**
  * @param array $descriptions
  * @dataProvider getDefaultDescriptionExceptionDataProvider
  *
  * @expectedException \LogicException
  * @expectedExceptionMessage There must be only one default description
  */
 public function testGetDefaultDescriptionException(array $descriptions)
 {
     $product = new Product();
     foreach ($descriptions as $description) {
         $product->addDescription($description);
     }
     $product->getDefaultDescription();
 }
 /**
  * @param Product $product
  * @return bool
  */
 public function isVisible(Product $product)
 {
     $visibility = $product->getVisibility() === Product::VISIBILITY_BY_CONFIG ? $this->configManager->get('orob2b_product.default_visibility') : $product->getVisibility();
     return $visibility === Product::VISIBILITY_VISIBLE;
 }
 /**
  * @param Product $product
  * @param Product $productCopy
  */
 protected function cloneChildObjects(Product $product, Product $productCopy)
 {
     foreach ($product->getUnitPrecisions() as $unitPrecision) {
         $productCopy->addUnitPrecision(clone $unitPrecision);
     }
     foreach ($product->getNames() as $name) {
         $productCopy->addName(clone $name);
     }
     foreach ($product->getDescriptions() as $description) {
         $productCopy->addDescription(clone $description);
     }
     if ($imageFile = $product->getImage()) {
         $imageFileCopy = $this->attachmentManager->copyAttachmentFile($imageFile);
         $productCopy->setImage($imageFileCopy);
     }
     $attachments = $this->attachmentProvider->getEntityAttachments($product);
     foreach ($attachments as $attachment) {
         $attachmentCopy = clone $attachment;
         $attachmentFileCopy = $this->attachmentManager->copyAttachmentFile($attachment->getFile());
         $attachmentCopy->setFile($attachmentFileCopy);
         $attachmentCopy->setTarget($productCopy);
         $this->doctrineHelper->getEntityManager($attachmentCopy)->persist($attachmentCopy);
     }
 }
示例#18
0
 /**
  * @return Product
  */
 protected function createProduct()
 {
     $product = new Product();
     $product->setSku('sku_001');
     return $product;
 }
 /**
  * @return array
  */
 public function submitProvider()
 {
     $product = new Product();
     $product->setSku('sku_test_001');
     $productUnitPrecision = new ProductUnitPrecision();
     $productUnitPrecision->setUnit((new ProductUnit())->setCode('kg'));
     $productUnitPrecision->setPrecision(5);
     $existingUnit = (new ProductUnit())->setCode('kg');
     $existingPrice = (new Price())->setValue(42)->setCurrency('USD');
     $product->addUnitPrecision($productUnitPrecision);
     /** @var PriceList $existingProductPriceList */
     $existingProductPriceList = $this->getEntity('OroB2B\\Bundle\\PricingBundle\\Entity\\PriceList', 1);
     $existingProductPrice = new ProductPrice();
     $existingProductPrice->setProduct($product)->setPriceList($existingProductPriceList)->setQuantity(123)->setUnit($existingUnit)->setPrice($existingPrice);
     /** @var PriceList $expectedPriceList */
     $expectedPriceList = $this->getEntity('OroB2B\\Bundle\\PricingBundle\\Entity\\PriceList', 2);
     $expectedUnit = (new ProductUnit())->setCode('item');
     $expectedPrice = (new Price())->setValue(43)->setCurrency('EUR');
     $expectedProductPrice = new ProductPrice();
     $expectedProductPrice->setPriceList($expectedPriceList)->setQuantity(124)->setUnit($expectedUnit)->setPrice($expectedPrice)->setProduct($product);
     $updatedExpectedProductPrice = clone $expectedProductPrice;
     $updatedExpectedProductPrice->setProduct($product);
     return ['product price with data' => ['defaultData' => (new ProductPrice())->setProduct($product)->setUnit($existingUnit), 'submittedData' => ['priceList' => 2, 'quantity' => 124, 'unit' => 'item', 'price' => ['value' => 43, 'currency' => 'EUR']], 'expectedData' => $expectedProductPrice], 'product price with precision' => ['defaultData' => $existingProductPrice, 'submittedData' => ['priceList' => 2, 'quantity' => 124, 'unit' => 'item', 'price' => ['value' => 43, 'currency' => 'EUR']], 'expectedData' => $updatedExpectedProductPrice, 'expectedOptions' => ['precision' => 5]]];
 }
 /**
  * @param Product $product
  * @param Locale $locale
  * @return LocalizedFallbackValue
  */
 protected function getLocalizedName(Product $product, Locale $locale)
 {
     $localizedName = null;
     foreach ($product->getNames() as $name) {
         $nameLocale = $name->getLocale();
         if ($nameLocale && $nameLocale->getId() === $locale->getId()) {
             $localizedName = $name;
             break;
         }
     }
     if (!$localizedName) {
         throw new \LogicException('At least one localized name must be defined');
     }
     return $localizedName;
 }
 /**
  * @param Product $product
  * @return array
  */
 protected function getProductUnits(Product $product = null)
 {
     $choices = [];
     if ($product) {
         foreach ($product->getUnitPrecisions() as $unitPrecision) {
             $choices[] = $unitPrecision->getUnit();
         }
     }
     return $choices;
 }
 /**
  * @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;
 }
示例#23
0
 /**
  * @param Product $product
  * @return ProductPrice
  */
 public function setProduct(Product $product)
 {
     $this->product = $product;
     $this->productSku = $product->getSku();
     return $this;
 }
示例#24
0
 /**
  * Set productReplacement
  *
  * @param Product $productReplacement
  * @return QuoteProduct
  */
 public function setProductReplacement(Product $productReplacement = null)
 {
     $this->productReplacement = $productReplacement;
     if ($productReplacement) {
         $this->productReplacementSku = $productReplacement->getSku();
     }
     return $this;
 }
 /**
  * Set product
  *
  * @param Product $product
  * @return RequestProduct
  */
 public function setProduct(Product $product = null)
 {
     $this->product = $product;
     if ($product) {
         $this->productSku = $product->getSku();
     }
     return $this;
 }
示例#26
0
 /**
  * Set product
  *
  * @param Product $product
  * @return $this
  */
 public function setProduct(Product $product = null)
 {
     if ($product && (!$this->product || $product->getId() !== $this->product->getId())) {
         $this->requirePriceRecalculation = true;
     }
     $this->product = $product;
     return $this;
 }
 /**
  * @param string $sku
  * @param bool $isReplacement
  * @return QuoteProduct
  */
 protected function createQuoteProduct($sku, $isReplacement = false)
 {
     $product = new Product();
     $product->setSku($sku);
     $quoteProduct = new QuoteProduct();
     if ($isReplacement) {
         $quoteProduct->setProductReplacement($product);
     } else {
         $quoteProduct->setProduct($product);
     }
     return $quoteProduct;
 }
 /**
  * @param Product $product
  *
  * @return Crawler
  */
 protected function getCrawler(Product $product)
 {
     return $this->client->request('GET', $this->getUrl('orob2b_shopping_list_line_item_frontend_add_widget', ['productId' => $product->getId(), '_widgetContainer' => 'dialog', '_wid' => 'test-uuid']));
 }