productRepository = $productRepository; $this->attributeFamilyRepository = $attributeFamilyRepository; $this->types = [ 'text', 'textarea', 'boolean', 'select', 'multiselect', 'datetime', 'date', 'price', 'image', 'file', 'checkbox', ]; } public function create() { $sku = 'teste-' . time(); $data = [ 'type' => 'simple', 'attribute_family_id' => 1, // Id do grupo de atributos, 'sku' => $sku ]; $product = $this->productRepository->create($data); $data['name'] = 'Product Example ' . time(); $data['url_key'] = $sku; $data['width'] = 10; $data['height'] = 10; $data['depth'] = 10; $data['weight'] = 1; $data['price'] = 120; // Get core Channel $channel = core()->getCurrentChannel(); $data['locale'] = core()->getCurrentLocale()->code; if ($brand = Attribute::where(['code' => 'brand'])->first()) { // Adiciona uma marca se tiver $data['brand'] = AttributeOption::where(['attribute_id' => $brand->id])->first()->id ?? ''; } $data['channel'] = $channel->code; $data['channels'] = [ 0 => $channel->id, ]; // Pega estoques $inventorySource = $channel->inventory_sources[0]; $data['inventories'] = [ $inventorySource->id => 10, ]; // Pega categorias $data['categories'] = [ 0 => $channel->root_category->id, ]; $updated = $this->productRepository->update($data, $product->id); return $updated; } /** * @param $code * @return \Illuminate\Support\Collection */ protected function getFamilyAttributes($code) { $attributeFamily = $this->attributeFamilyRepository->findWhere([ 'code' => $code, ]); $attributes = collect(); if ($attributeFamily->count()) { $attributeGroups = $attributeFamily->first()->attribute_groups; foreach ($attributeGroups as $attributeGroup) { foreach ($attributeGroup->custom_attributes as $customAttribute) { $attributes->push($customAttribute); } } } return $attributes; } }