/**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $locator = $this->container->get('file_locator');
     $filePath = $locator->locate('@OroB2BPricingBundle/Migrations/Data/Demo/ORM/data/product_prices.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));
         $product = $this->getProductBySku($manager, $row['sku']);
         $productUnit = $this->getProductUnit($manager, $row['unitCode']);
         $priceList = $this->getPriceList($manager, $row['priceListName']);
         $price = Price::create($row['price'], $row['currency']);
         $productPrice = new ProductPrice();
         $productPrice->setProduct($product)->setUnit($productUnit)->setPriceList($priceList)->setQuantity($row['quantity'])->setPrice($price);
         $manager->persist($productPrice);
         $productPrice10 = clone $productPrice;
         $productPrice10->setQuantity($row['quantity'] * 10)->setPrice($price->setValue($price->getValue() * 0.95));
         $manager->persist($productPrice10);
         $productPrice20 = clone $productPrice;
         $productPrice20->setQuantity($row['quantity'] * 20)->setPrice($price->setValue($price->getValue() * 0.9));
         $manager->persist($productPrice20);
         $productPrice50 = clone $productPrice;
         $productPrice50->setQuantity($row['quantity'] * 50)->setPrice($price->setValue($price->getValue() * 0.85));
         $manager->persist($productPrice50);
         $productPrice100 = clone $productPrice;
         $productPrice100->setQuantity($row['quantity'] * 100)->setPrice($price->setValue($price->getValue() * 0.8));
         $manager->persist($productPrice100);
     }
     fclose($handler);
     $manager->flush();
 }
Ejemplo n.º 2
0
 public function testGetProductSku()
 {
     $product = new Product();
     $product->setSku('test');
     $price = new ProductPrice();
     $price->setProduct($product);
     $this->assertEquals($product->getSku(), $price->getProductSku());
 }
 /**
  * @param ProductPrice $entity
  */
 protected function loadProduct(ProductPrice $entity)
 {
     if ($entity->getProduct()) {
         /** @var Product $product */
         $product = $this->findExistingEntity($entity->getProduct());
         if ($product) {
             $entity->setProduct($product);
         } else {
             $this->fieldHelper->setObjectValue($entity, 'product', null);
             $this->fieldHelper->setObjectValue($entity, 'productSku', null);
         }
     }
 }
 /**
  * @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;
 }
 /**
  * @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 int $productId
  * @param float $value
  * @param string $currency
  * @return ProductPrice
  */
 protected function createPrice($productId, $value, $currency)
 {
     $product = new Product();
     $reflection = new \ReflectionProperty(get_class($product), 'id');
     $reflection->setAccessible(true);
     $reflection->setValue($product, $productId);
     $price = new ProductPrice();
     $price->setProduct($product)->setPrice(Price::create($value, $currency));
     return $price;
 }
 /**
  * @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]]];
 }
 /**
  * @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]];
 }
Ejemplo n.º 9
0
 /**
  * @param string  $key
  * @param ProductPrice $entity
  */
 public function fillEntityData($key, $entity)
 {
     $entity->setProduct($this->createProduct())->setPrice($this->createPrice())->setUnit($this->createProductUnit())->setQuantity(42);
 }