Exemplo n.º 1
0
 /**
  * Process fields after the actual model is saved(inserted or updated)
  * @param array $fields
  * @return void
  */
 public function processImportAfterSave(array $fields, $multipleValuesDelimiter, array $additionalFields)
 {
     $categories = $this->unpackCategories($fields, $multipleValuesDelimiter, $additionalFields);
     if ($categories === false) {
         $categories = [$this->main_category_id];
     }
     $this->saveCategoriesBindings($categories);
     $images = isset($fields['images']) ? $fields['images'] : (isset($fields['image']) ? $fields['image'] : false);
     if ($images !== false) {
         if (strpos($images, $multipleValuesDelimiter) > 0) {
             $images = explode($multipleValuesDelimiter, $images);
         } elseif (strpos($multipleValuesDelimiter, '/') === 0) {
             $images = preg_split($multipleValuesDelimiter, $images);
         } else {
             $images = [$images];
         }
         $input_array = [];
         foreach ($images as $image_src) {
             $input_array[] = ['filename' => $image_src];
         }
         if (count($input_array) > 0) {
             Image::replaceForModel($this, $input_array);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Process fields after the actual model is saved(inserted or updated)
  * @param array $fields
  * @return void
  */
 public function processImportAfterSave(array $fields, $multipleValuesDelimiter, array $additionalFields)
 {
     $categories = $this->unpackCategories($fields, $multipleValuesDelimiter, $additionalFields);
     if ($categories === false) {
         $categories = [$this->main_category_id];
     }
     $this->saveCategoriesBindings($categories);
     $images = isset($fields['images']) ? $fields['images'] : (isset($fields['image']) ? $fields['image'] : false);
     if ($images !== false) {
         if (strpos($images, $multipleValuesDelimiter) > 0) {
             $images = explode($multipleValuesDelimiter, $images);
         } elseif (strpos($multipleValuesDelimiter, '/') === 0) {
             $images = preg_split($multipleValuesDelimiter, $images);
         } else {
             $images = [$images];
         }
         $input_array = [];
         foreach ($images as $image_src) {
             $input_array[] = ['filename' => $image_src];
         }
         if (count($input_array) > 0) {
             Image::replaceForModel($this, $input_array);
         }
     }
     if (isset($additionalFields['relatedProducts'])) {
         if (isset($additionalFields['relatedProducts']['processValuesAs'], $fields['relatedProducts'])) {
             $ids = explode($multipleValuesDelimiter, $fields['relatedProducts']);
             $this->relatedProductsArray = $ids;
             $this->saveRelatedProducts();
             //                $this->unlinkAll('relatedProducts', true);
             //
             //                foreach ($ids as $index => $id) {
             //                    $product = Product::findById($id);
             //                    $this->link('relatedProduct', $product, ['sort_order'=>$index]);
             //                }
         }
     }
 }