Exemplo n.º 1
0
 public function run()
 {
     $faker = TestCase::faker();
     for ($i = 1; $i <= 10; $i++) {
         $productImage = ProductImage::create(array('product_id' => TestCase::getFixture('products.product_1')->id, 'name' => $faker->name));
         TestCase::addFixture('product_images.product_image_' . $i, $productImage);
     }
 }
Exemplo n.º 2
0
 /**
  * Create a new ProductImage.
  *
  * @example
  *     $product = Subbly\Model\ProductImage;
  *     Subbly::api('subbly.product_category')->create($productImage);
  *
  *     Subbly::api('subbly.product_category')->create(array(
  *         'firstname' => 'Jon',
  *         'lastname'  => 'Snow',
  *     ));
  *
  * @param \Subbly\Model\ProductImage|array $productImage
  * @param \Subbly\Model\Product|null       $product
  *
  * @return \Subbly\Model\ProductImage
  *
  * @throws \Subbly\Api\Service\Exception
  *
  * @api
  */
 public function create($productImage, $product)
 {
     if (!$product instanceof Product) {
         $product = $this->api('subbly.product')->find($product);
     }
     if (is_array($productImage)) {
         $productImage = new ProductImage($productImage);
     }
     if ($productImage instanceof ProductImage) {
         if ($this->fireEvent('creating', array($productImage)) === false) {
             return false;
         }
         $productImage->product()->associate($product);
         $productImage->setCaller($this);
         $productImage->save();
         $this->fireEvent('created', array($productImage));
         $productImage = $this->find($productImage->uid);
         return $productImage;
     }
     throw new Exception(sprintf(Exception::CANT_CREATE_MODEL, $this->modelClass, $this->name()));
 }