protected function save(waRequestFile $file)
 {
     if (!$this->model) {
         $this->model = new shopProductSkusModel();
     }
     $field = array('id' => waRequest::post('sku_id', null, waRequest::TYPE_INT), 'product_id' => waRequest::post('product_id', null, waRequest::TYPE_INT));
     $data = array('file_size' => $file->size, 'file_name' => $file->name);
     $this->model->updateByField($field, $data);
     $file_path = shopProduct::getPath($field['product_id'], "sku_file/{$field['id']}." . pathinfo($file->name, PATHINFO_EXTENSION));
     if (file_exists($file_path) && !is_writable($file_path) || !file_exists($file_path) && !waFiles::create($file_path)) {
         $data = array('file_size' => 0, 'file_name' => '');
         $this->model->updateByField($field, $data);
         throw new waException(sprintf("The insufficient file write permissions for the %s folder.", substr($file_path, strlen($this->getConfig()->getRootPath()))));
     }
     $file->moveTo($file_path);
     return array('name' => $file->name, 'size' => waFiles::formatSize($file->size));
 }
Esempio n. 2
0
 public function delete(array $product_ids)
 {
     if (wa()->getEnv() !== 'cli') {
         $delete_ids = $this->filterAllowedProductIds($product_ids);
     } else {
         $delete_ids = $product_ids;
     }
     // remove files
     foreach ($delete_ids as $product_id) {
         try {
             waFiles::delete(shopProduct::getPath($product_id, null, false));
             waFiles::delete(shopProduct::getPath($product_id, null, true));
         } catch (waException $e) {
         }
     }
     if (empty($delete_ids)) {
         return false;
     }
     $params = array('ids' => $delete_ids);
     /**
      * @event product_delete
      * @param array [string]mixed $params
      * @param array [string]array $params['ids'] Array of IDs of deleted product entries
      * @return void
      */
     wa()->event('product_delete', $params);
     // remove from related models
     foreach (array(new shopProductFeaturesModel(), new shopProductImagesModel(), new shopProductReviewsModel(), new shopProductServicesModel(), new shopProductSkusModel(), new shopProductStocksModel(), new shopProductStocksLogModel(), new shopProductTagsModel(), new shopCategoryProductsModel(), new shopSetProductsModel(), new shopSearchIndexModel(), new shopProductFeaturesSelectableModel(), new shopProductParamsModel(), new shopCartItemsModel()) as $model) {
         $model->deleteByProducts($delete_ids);
     }
     $type_ids = $this->select('DISTINCT `type_id`')->where($this->getWhereByField($this->id, $delete_ids))->fetchAll('type_id');
     // remove records
     if ($this->deleteById($delete_ids)) {
         $type_model = new shopTypeModel();
         $type_model->recount(array_keys($type_ids));
         if ($cache = wa('shop')->getCache()) {
             $cache->deleteGroup('sets');
         }
         return $delete_ids;
     }
     return false;
 }
Esempio n. 3
0
 public static function getPath($sku)
 {
     return empty($sku['file_name']) ? null : shopProduct::getPath($sku['product_id'], "sku_file/{$sku['id']}." . pathinfo($sku['file_name'], PATHINFO_EXTENSION));
 }
Esempio n. 4
0
 /**
  * TODO change
  * 
  * Returns path to original product image
  * 
  * @param array $image Key-value image data object
  * @return string
  */
 public static function getOriginalPath($image)
 {
     return shopProduct::getPath($image['product_id'], "images/{$image['id']}.original.{$image['ext']}");
 }
 public function deleteByProducts(array $product_ids, $hard = false)
 {
     if ($hard) {
         foreach ($product_ids as $product_id) {
             waFiles::delete(shopProduct::getPath($product_id, 'images', false));
             waFiles::delete(shopProduct::getPath($product_id, 'images', true));
         }
     }
     $this->deleteByField('product_id', $product_ids);
 }