/**
  * Assign the image to the product using the filename given in the CSV, and save it against the product
  *
  * @param Product\Product $product
  * @param array $row
  * @param array $options
  * @param string $type
  */
 public function save(Product\Product $product, array $row, $options = [], $type = 'default')
 {
     $key = $this->_headingKeys->getKey(self::HEADING_KEY);
     if (!array_key_exists($key, $row)) {
         throw new \LogicException('Key `' . $key . '` does not exist in row');
     }
     $filename = (string) $row[$key];
     if ($filename !== '') {
         $image = $this->_imageAssignor->assignByName($filename, $product, $options, $type);
         $this->_imageCreate->create($image);
     }
 }
 public function setStockLevel(Unit $unit, array $row, $location = 'web')
 {
     $stockKey = $this->_headingKeys->getKey('stock');
     if (!is_string($location) && !$location instanceof Location\Location) {
         throw new \InvalidArgumentException('Location must be either a string or an instance of Location');
     } elseif (!array_key_exists($stockKey, $row)) {
         throw new \LogicException('No stock column in row!');
     }
     $stockLevel = (int) $row[$stockKey];
     if ($stockLevel > 0) {
         $location = $location instanceof Location\Location ? $location : $this->_locations->get($location);
         $this->_stockManager->setReason($this->_reason);
         $this->_stockManager->set($unit, $location, $stockLevel);
     }
 }
 /**
  * @param array $rows
  *
  * @return bool
  */
 public function validBrands(array $rows)
 {
     $valid = true;
     if ($rows !== $rows || null === $this->_valid) {
         $this->_rows = $rows;
         foreach ($rows as $row) {
             $key = $this->_headingKeys->getKey(self::BRAND);
             if (empty($row[$key])) {
                 $valid = false;
                 break;
             }
         }
         $this->_valid = $valid;
     }
     return $this->_valid;
 }
 private function _setData(array $row)
 {
     foreach ($row as $key => $value) {
         $key = $this->_headingKeys->getKey($key);
         if ($value && property_exists($this->_unit, $key)) {
             $this->_unit->{$key} = $value;
         }
     }
     return $this;
 }
 private function _addData(array $data)
 {
     $this->_addProductDefaults();
     foreach ($data as $key => $value) {
         $key = $this->_headingKeys->getKey($key);
         if ($value !== '' && property_exists($this->_product, $key)) {
             $this->_product->{$key} = $value;
         }
     }
 }
 /**
  * Loop through rows and identify unique variant names
  *
  * @param array $rows
  */
 private function _setVariantNames(array $rows)
 {
     foreach ($this->_variantKeys as $variantKey) {
         $variantKeyTrans = $this->_headingKeys->getKey($variantKey);
         if (!array_key_exists($variantKey, $this->_variantNames)) {
             $this->_variantNames[$variantKey] = [];
         }
         foreach ($rows as $product) {
             foreach ($product as $row) {
                 $this->_validateRow($row, $variantKeyTrans);
                 $variantName = $row[$variantKeyTrans];
                 $variantName = ucfirst(strtolower($variantName));
                 if (!empty($variantName) && !in_array($variantName, $this->_variantNames[$variantKey])) {
                     $this->_variantNames[$variantKey][] = $variantName;
                 }
             }
         }
         $this->_variantNames[$variantKey] = implode(', ', $this->_variantNames[$variantKey]);
     }
 }