oc-shopaholic/oc-shopaholic-plugin

View on GitHub
classes/import/ImportBrandModelFromCSV.php

Summary

Maintainability
A
50 mins
Test Coverage
<?php namespace Lovata\Shopaholic\Classes\Import;

use Lovata\Toolbox\Classes\Helper\AbstractImportModelFromCSV;

use Lovata\Shopaholic\Models\Brand;

/**
 * Class ImportBrandModelFromCSV
 * @package Lovata\Shopaholic\Classes\Import
 * @author  Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
 */
class ImportBrandModelFromCSV extends AbstractImportModelFromCSV
{
    const MODEL_CLASS = Brand::class;

    /** @var Brand */
    protected $obModel;

    /**
     * ImportBrandModelFromCSV constructor.
     */
    public function __construct()
    {
        $this->arExistIDList = (array) Brand::whereNotNull('external_id')->pluck('external_id', 'id')->all();
        $this->arExistIDList = array_filter($this->arExistIDList);
    }

    /**
     * Prepare array of import data
     */
    protected function prepareImportData()
    {
        $this->setActiveField();

        $this->initPreviewImage();
        $this->initImageList();

        parent::prepareImportData();
    }

    /**
     * Process model object after creation/updating
     */
    protected function processModelObject()
    {
        $this->importPreviewImage();
        $this->importImageList();
    }
}