Stores a product.

@param ProductContract $product
@param array $attributes
@return bool
172701
public function save(ProductContract $product, array $attributes = [])
    {
        $result = $product->save();

        $details = [];
        foreach ($attributes as $key => $value) {
            if ($value) {
                $details[$key] = compact('value');
            }
        }
        $product->attributes()->sync($details);

        return $result;
    }
144314
protected function updateProductsFeatures(array $attributes, $products)
    {
        $products->each(function ($item, $key) use ($attributes, $products) {
            $item->update(['features' => json_encode($attributes[$item->id])]);
            $item->save();
        });
    }
1321531
public function update(array $attributes = [], array $options = [])
    {
        $relations = [];
        $transaction = false;

        foreach ($attributes as $key => $value) {
            if ($this->isRelationMapped($key)) {
                $relations[$key] = $value;
                unset($attributes[$key]);
            }
        }

        if (count($relations) > 0) {
            DB::beginTransaction();
            $transaction = true;
        }

        try {
            $userId = SessionUtility::getCurrentUserId();
            if ($userId && static::isField('last_modified_by_id')) {
                $this->last_modified_by_id = $userId;
            }
            $updated = parent::update($attributes);

            if ($updated && $this->exists && count($relations) > 0) {
                foreach ($relations as $name => $value) {
                    $relatedModel = $this->getReferencingModel($name);

                    if (RelationSchema::HAS_ONE === $this->getReferencingType($name)) {
                        $hasOne = $this->getHasOneByRelationName($name);
                        $this->saveHasOneData($relatedModel, $hasOne, $value, $name);
                    } elseif (RelationSchema::HAS_MANY === $this->getReferencingType($name)) {
                        $hasMany = $this->getHasManyByRelationName($name);
                        $this->saveHasManyData($relatedModel, $hasMany, $value, $name);
                    }
                }
            }

            if ($transaction) {
                DB::commit();
            }
        } catch (\Exception $e) {
            if ($transaction) {
                DB::rollBack();
            }

            throw $e;
        }

        return $updated;
    }
1221583
public function store(UploadedFile $file, array $attributes = [])
    {
        $type = $this->resolveType($file);

        return $this->submit($file, $type, $attributes);
    }
513919
public function create(array $attributes = [])
    {
        $results = $this->make($attributes);

        $this->getMapper()->store($results);

        return $results;
    }
272967
public function storeObjectAttribute($objectAttribute)
    {
        /** @var \Netgen\Bundle\EzSyliusBundle\Core\FieldType\SyliusProduct\Value $value */
        $value = $objectAttribute->content();

        $this->storage->storeFieldData($objectAttribute, $value);
    }
296867
public function add(array $product, array $data)
    {
        $result = array();
        $this->hook->attach('product.compare.add.product.before', $product, $data, $result, $this);

        if (!empty($result)) {
            return (array) $result;
        }

        if (!$this->compare->add($product['product_id'])) {
            return $this->getResultError();
        }

        $result = $this->getResultAdded();
        $this->hook->attach('product.compare.add.product.after', $product, $data, $result, $this);
        return (array) $result;
    }
198778
public function fill(Identifiable $config, array $attributes)
    {
        if (!$attributes) {
            return false;
        }

        foreach ($attributes as $key => $value) {
            if (in_array($key, ['collection', 'assets', 'files'])) {
                $this->addCollection($config, $value, $attributes);
                continue;
            }
            $this->addToConfig($config, $key, $value);
        }

        return true;
    }
413315
public static function create(array $attributes = [])
    {
        $site_id = site()->id;

        $contact = new static;

        $fillable = $contact->getFillable();

        foreach (array_only($attributes, $fillable) as $key => $value) {

            if  (is_array($value)) {
                $value = json_encode($value);
            }
            $row = Setting::privateOnly()->firstOrNew(compact('key', 'site_id'));
            $row->fill(compact('value'));
            $row->save();
        }

        return true;
    }
22730
public function update($product)
    {
        $productId = "";

        if (is_array($product)) {
            $productId = $product["id"];
            unset($product["id"]);
        }
        elseif (is_object($product)) {
            $productId = $product->id;
            unset($product->id);
        }

        return $this->client->put("/products/" . rawurlencode($productId), $product);
    }
260399
public function update(array $attributes = array())
    {
        if (! $this->exists) {
            return $this->newQuery()->update($attributes);
        }

        return $this->fill($attributes)->save();
    }
3499
private function initStoreProductData($productId, $storeId)
    {
        if (!array_key_exists($productId, $this->attributeData)) {
            $this->attributeData[$productId] = [];
        }

        if (!array_key_exists($storeId, $this->attributeData[$productId])) {
            $this->attributeData[$productId][$storeId] = [];
        }
    }
430674
private function formatProductAttributes(array $attributes) {

    $formatted = [];

    foreach ($attributes as $name => $value) {
      if (is_string($value)) {
        $valueAsString = $value;
      }
      else {
        // Does the key=>value store module expect serialize?
        // (I would prefer JSON)
        // >> Yes. (But are we using the key=>value store for this?)
        // Can we pass it the object and get 'auto serialize/unserialize'?
        // >> Maybe.
        if (is_array($value) || is_object($value)) {
          $valueAsString = serialize($value);
        }
        else {
          // 'Trust' PHP's type-casting for now.
          $valueAsString = (string) $value;
        }
      }

      $formatted[] = [
        'key' => $name,
        'value' => $valueAsString,
      ];
    }

    return $formatted;
  }
424218
public function setAttributeArray(array $attributes = null)
    {
        if (!is_array($attributes) || empty($attributes)) {
            return;
        }

        foreach ($attributes as $name => $value) {
            $this->setAttribute($name, $value);
        }
    }
1166243
public function setAttributes($attributes)
    {
        if ($attributes === null) {
            $this->attributes = [];

            return $this;
        }

        if (is_array($attributes)) {
            $this->attributes = $attributes;

            return $this;
        }

        $attributes = explode(',', $attributes);
        $attributes = $this->relationsToArray($attributes);

        $this->attributes = $attributes;

        return $this;
    }
1141883
public function haveRecord($model, $attributes = [])
    {
        /** @var $record \yii\db\ActiveRecord  * */
        $record = \Yii::createObject($model);
        $record->setAttributes($attributes, false);
        $res = $record->save(false);
        if (!$res) {
            $this->fail("Record $model was not saved");
        }
        return $record->primaryKey;
    }
294079
public function update( array $attributes = [], array $options = [] )
    {
        if( ! $this->exists ) {
            return false;
        }
        $updated = $this->fill( $attributes )->save( $options );
        self::$lastUpdated = $this;
        return $updated;
    }