/**
  * {@inheritdoc}
  */
 protected function addItem(Product $product, $entity, array $itemData = [])
 {
     if (!$entity instanceof RFPRequest) {
         return;
     }
     $requestProductItem = new RequestProductItem();
     $requestProduct = new RequestProduct();
     $requestProduct->setProduct($product)->addRequestProductItem($requestProductItem);
     if (array_key_exists(ProductDataStorage::PRODUCT_QUANTITY_KEY, $itemData)) {
         $requestProductItem->setQuantity($itemData[ProductDataStorage::PRODUCT_QUANTITY_KEY]);
     }
     $this->fillEntityData($requestProductItem, $itemData);
     if (!$requestProductItem->getProductUnit()) {
         /** @var ProductUnitPrecision $unitPrecision */
         $unitPrecision = $product->getUnitPrecisions()->first();
         if (!$unitPrecision) {
             return;
         }
         /** @var ProductUnit $unit */
         $unit = $unitPrecision->getUnit();
         if (!$unit) {
             return;
         }
         $requestProductItem->setProductUnit($unit);
     }
     if ($requestProductItem->getProductUnit()) {
         $entity->addRequestProduct($requestProduct);
     }
 }
 /**
  * @depends testProperties
  */
 public function testSetProduct()
 {
     $product = (new Product())->setSku('rfp-sku');
     $requestProduct = new RequestProduct();
     $this->assertNull($requestProduct->getProductSku());
     $requestProduct->setProduct($product);
     $this->assertEquals($product->getSku(), $requestProduct->getProductSku());
 }
 /**
  * "Success" form handler
  *
  * @param ShoppingList $entity
  * @return bool
  */
 protected function onSuccess(ShoppingList $entity)
 {
     $rfpRequest = new RFPRequest();
     $rfpRequest->setFirstName($this->user->getFirstName())->setLastName($this->user->getLastName())->setEmail($this->user->getEmail())->setPhone('')->setRole('')->setBody('')->setCompany($this->user->getOrganization() ? $this->user->getOrganization()->getName() : '')->setAccountUser($this->user)->setAccount($this->user->getAccount())->setStatus($this->requestStatus);
     foreach ($entity->getLineItems() as $shoppingListLineItem) {
         $requestProduct = new RequestProduct();
         $requestProduct->setProduct($shoppingListLineItem->getProduct());
         $requestProductItem = new RequestProductItem();
         $requestProductItem->setQuantity($shoppingListLineItem->getQuantity())->setProductUnit($shoppingListLineItem->getUnit());
         $requestProduct->addRequestProductItem($requestProductItem);
         $rfpRequest->addRequestProduct($requestProduct);
     }
     try {
         $this->manager->persist($rfpRequest);
         $this->manager->flush();
         $this->rfpRequest = $rfpRequest;
     } catch (DBALException $e) {
         $this->exception = $e;
         return false;
     }
     return true;
 }
Ejemplo n.º 4
0
 /**
  * @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);
     }
 }