public function run() { ProductImage::truncate(); $image = array('lib/images/products/product-gallery-01.jpg', 'lib/images/products/product-gallery-02.png', 'lib/images/products/product-gallery-03.jpg', 'lib/images/products/product-gallery-04.jpg'); $image_thumb = array('lib/images/products/gallery-thumb-01.jpg', 'lib/images/products/gallery-thumb-02.jpg', 'lib/images/products/gallery-thumb-03.jpg', 'lib/images/products/gallery-thumb-04.jpg'); for ($i = 1; $i <= 30; $i++) { for ($j = 0; $j < 4; $j++) { ProductImage::create(array('image' => $image[$j], 'image_small' => $image_thumb[$j], 'product_id' => $i)); } } }
public function run() { ProductImage::create(['product_id' => '1', 'image_url' => '01.jpg']); ProductImage::create(['product_id' => '1', 'image_url' => '02.jpg']); ProductImage::create(['product_id' => '1', 'image_url' => '03.jpg']); ProductImage::create(['product_id' => '2', 'image_url' => '11.jpg']); ProductImage::create(['product_id' => '3', 'image_url' => '21.jpg']); ProductImage::create(['product_id' => '4', 'image_url' => '31.jpg']); ProductImage::create(['product_id' => '5', 'image_url' => '41.jpg']); ProductImage::create(['product_id' => '6', 'image_url' => '51.jpg']); ProductImage::create(['product_id' => '7', 'image_url' => '61.jpg']); ProductImage::create(['product_id' => '8', 'image_url' => '71.jpg']); ProductImage::create(['product_id' => '9', 'image_url' => '81.jpg']); ProductImage::create(['product_id' => '10', 'image_url' => '91.jpg']); }
public function post() { $input = Input::all(); $sessionId = Common::checkSessionLogin($input); //check user active $checkUser = User::find($input['user_id'])->status; if (isset($checkUser) && $checkUser == INACTIVE) { throw new Prototype\Exceptions\UserStatusErrorException(); } // create product $inputSubmit = ['name' => $input['name'], 'user_id' => $input['user_id'], 'category_id' => $input['category_id'], 'type_id' => $input['type_id'], 'price_id' => CommonProduct::getPriceId($input['price']), 'price' => $input['price'], 'lat' => $input['lat'], 'long' => $input['long'], 'description' => $input['description'], 'avatar' => $input['avatar'], 'address' => $input['address'], 'city_id' => $input['city_id'], 'city' => Common::getModelField($input['city_id'], 'City', 'name'), 'position' => 1, 'status' => INACTIVE, 'start_time' => Carbon\Carbon::now()]; $id = Product::create($inputSubmit)->id; // images product if (isset($input['image_url']) && count($input['image_url']) > 0) { foreach ($input['image_url'] as $key => $value) { $inputImage = array('product_id' => $id, 'image_url' => $value); ProductImage::create($inputImage); } } return Common::returnData(200, SUCCESS, $input['user_id'], $sessionId); }
private function _uploadImages(Product &$product, $param) { //upload images if (isset($param->CallbackParameter->images) && count($images = $param->CallbackParameter->images) > 0) { foreach ($images as $image) { if (($assetId = trim($image->imageAssetId)) === '') { if ($image->active === true) { $data = explode(',', $image->data); $asset = Asset::registerAsset(trim($image->filename), base64_decode($data[1]), Asset::TYPE_PRODUCT_IMG); ProductImage::create($product, $asset); } //if it's deactivated one, ignore } else { if (!($asset = Asset::getAsset($assetId)) instanceof Asset) { continue; } } if ($image->active === false) { ProductImage::remove($product, $asset); } } } return $this; }
/** * Adding a product image to the product * * @param Asset $asset The asset object that reprents the image * * @return Product */ public function addImage(Asset $asset) { $image = ProductImage::create($this, $asset); if (isset($this->_cache['images'])) { $this->_cache['images'][] = $image; } return $this; }