<?php

namespace Webkul\ShopifyBundle\Connector\Writer;

use Webkul\ShopifyBundle\Services\ShopifyConnector;

$obj = new \Webkul\ShopifyBundle\Listener\LoadingClassListener();
$obj->checkVersionAndCreateClassAliases();
/**
 * Add resources to shopify
 *
 * @author    Webkul
 * @copyright 2010-2017 Webkul pvt. ltd.
 * @license   https://store.webkul.com/license.html
 */
class BaseWriter implements \StepExecutionAwareInterface
{
    protected $connectorService;

    /**
     * {@inheritdoc}
     */
    public function setStepExecution(\StepExecution $stepExecution)
    {
        $this->stepExecution = $stepExecution;
        if (!empty($this->connectorService) && $this->connectorService instanceof ShopifyConnector) {
            $this->connectorService->setStepExecution($stepExecution);
        }
        
        $filters = $this->stepExecution->getJobParameters()->get('filters');
        if (isset($filters[0]['context']['locale'])) {
            $credential = $this->connectorService->getCredentials();
            $this->storeLocaleMapping = $credential['storelocaleMapping'];
            $localeValues = [];
            foreach($this->storeLocaleMapping as $akeneoLocales) {
                if (!in_array($akeneoLocales, $localeValues)) {
                    $localeValues[] = $akeneoLocales;
                    $this->jobLocales[] = $akeneoLocales;
                }
            }
        } else {
            $this->jobLocales = $filters['structure']['locales'];
        }
    }

    public function __construct(ShopifyConnector $connectorService)
    {
        $this->connectorService = $connectorService;
    }
}
