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