ProductCollectionImport.php
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Models; |
| 4 | |
| 5 | use SureCart\Models\Concerns\ImportModel; |
| 6 | |
| 7 | /** |
| 8 | * Product import model |
| 9 | */ |
| 10 | class ProductCollectionImport extends ImportModel { |
| 11 | /** |
| 12 | * Rest API endpoint. |
| 13 | * |
| 14 | * @var string |
| 15 | */ |
| 16 | protected $endpoint = 'imports/product_collections'; |
| 17 | |
| 18 | /** |
| 19 | * Set the data attribute as an array of Product models. |
| 20 | * Accepts an iterable of attribute arrays/Products or a single Product instance. |
| 21 | * |
| 22 | * @param mixed $value Iterable of product attributes or Product instance. |
| 23 | * |
| 24 | * @return void |
| 25 | */ |
| 26 | public function setDataAttribute( $value ) { |
| 27 | $models = []; |
| 28 | if ( ! empty( $value ) && is_array( $value ) ) { |
| 29 | foreach ( $value as $attributes ) { |
| 30 | $models[] = is_a( $attributes, ProductCollection::class ) ? $attributes : new ProductCollection( $attributes ); |
| 31 | } |
| 32 | $value = $models; |
| 33 | } |
| 34 | $this->attributes['data'] = $value; |
| 35 | } |
| 36 | } |
| 37 |