示例#1
0
 /**
  * create new products and inventory items
  * @param array $data
  * @return Product $product
  */
 private function createProduct(array $data)
 {
     $product = new Product();
     $product->setSku($data['sku']);
     $product->setPrice($data['price']);
     $product->setName($data['name']);
     $inventoryItem = new InventoryItem();
     $inventoryItem->setProduct($product);
     $inventoryItem->setWarehouse($this->defaultWarehouse);
     $inventoryItem->setQuantity($data['stock_level']);
     $product->getInventoryItems()->add($inventoryItem);
     $status = $this->getReference('product_status_' . $data['status']);
     $product->setStatus($status);
     $channels = explode(';', $data['channel']);
     foreach ($channels as $channelId) {
         $channel = $this->getReference('marello_sales_channel_' . (int) $channelId);
         $product->addChannel($channel);
     }
     $this->manager->persist($product);
     return $product;
 }