active brands
This commit is contained in:
parent
adc7001963
commit
c640d7cf59
|
|
@ -12,13 +12,11 @@ use Webkul\Marketplace\Repositories\SellerRepository;
|
|||
|
||||
class IntegrationController extends Controller
|
||||
{
|
||||
protected $productRepository;
|
||||
protected $sellerRepository;
|
||||
|
||||
public function __construct(ProductRepository $productRepository, SellerRepository $sellerRepository)
|
||||
public function __construct(protected ProductRepository $productRepository,
|
||||
protected SellerRepository $sellerRepository)
|
||||
{
|
||||
$this->sellerRepository = $sellerRepository;
|
||||
$this->productRepository = $productRepository;
|
||||
|
||||
}
|
||||
|
||||
public function store(){
|
||||
|
|
@ -63,7 +61,8 @@ class IntegrationController extends Controller
|
|||
return response()->json(['errors'=>$validation->getMessageBag()->all()],422);
|
||||
}
|
||||
|
||||
if($product = $this->productRepository->findOneByField('product_number',$data['product_number'])){//product_group_id
|
||||
if($product = $this->productRepository->findOneByField('sku',$data['product_group_id']))
|
||||
{//product_group_id
|
||||
return response()->json(['success'=>true,'product_id' => $product->id]);
|
||||
}
|
||||
elseif($product = $this->productRepository->create($data)){
|
||||
|
|
|
|||
|
|
@ -135,53 +135,26 @@ class ImportRepository extends \Webkul\Core\Eloquent\Repository
|
|||
foreach($attributes as $code => $value){
|
||||
$attribute = $this->attributeRepository->findOneByField('code', $code);
|
||||
|
||||
if ($attribute->value_per_channel) {
|
||||
if ($attribute->value_per_locale) {
|
||||
foreach (core()->getAllChannels() as $channel) {
|
||||
foreach (core()->getAllLocales() as $locale) {
|
||||
$this->attributeValueRepository->create([
|
||||
'product_id' => $product->id,
|
||||
'attribute_id' => $attribute->id,
|
||||
'channel' => $channel->code,
|
||||
'locale' => $locale->code,
|
||||
'value' => $value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach (core()->getAllChannels() as $channel) {
|
||||
$this->attributeValueRepository->create([
|
||||
'product_id' => $product->id,
|
||||
'attribute_id' => $attribute->id,
|
||||
'channel' => $channel->code,
|
||||
'value' => $value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($attribute->value_per_locale) {
|
||||
foreach (core()->getAllLocales() as $locale) {
|
||||
$this->attributeValueRepository->create([
|
||||
'product_id' => $product->id,
|
||||
'attribute_id' => $attribute->id,
|
||||
'locale' => $locale->code,
|
||||
'value' => $value,
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
$attr = [
|
||||
'product_id' => $product->id,
|
||||
'attribute_id' => $attribute->id,
|
||||
'value' => $value,
|
||||
];
|
||||
$this->attributeValueRepository->create($attr);
|
||||
}catch (\Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
$attr = [
|
||||
'product_id' => $product->id,
|
||||
'attribute_id' => $attribute->id,
|
||||
'value' => $value
|
||||
];
|
||||
|
||||
}
|
||||
if($attribute->value_per_channel){
|
||||
$attr['channel'] = config('app.channel');
|
||||
}
|
||||
|
||||
if ($attribute->value_per_locale){
|
||||
foreach (core()->getAllLocales() as $locale){
|
||||
$attr['locale'] = $locale->code;
|
||||
$this->attributeValueRepository->create($attr);
|
||||
}
|
||||
|
||||
}else{
|
||||
$this->attributeValueRepository->create($attr);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -270,7 +270,7 @@ class ProductRepository extends WProductRepository
|
|||
public function create($data){
|
||||
$time_start = microtime(true);
|
||||
|
||||
$product['sku'] = 'G-'.$data['product_group_id'];
|
||||
$product['sku'] = $data['product_group_id'];
|
||||
// return array_map(fn($value): int => $value * 2, range(1, 5));
|
||||
|
||||
$product['type'] = (!empty($data['color_variants']) || !empty($data['size_variants'])) ? 'configurable':'simple';
|
||||
|
|
@ -348,7 +348,9 @@ class ProductRepository extends WProductRepository
|
|||
$description = implode(array_map(fn($value): string => '<p>' . $value['description'] . '</p>', $colorVariant['descriptions']));
|
||||
if (!empty($colorVariant['size_variants'])) {
|
||||
foreach ($colorVariant['size_variants'] as $sizeVariant) {
|
||||
if($variant = $this->createVariant($parentProduct, "{$colorVariant['product_number']}-{$sizeVariant['itemNumber']}"))
|
||||
$variant = $this->createVariant($parentProduct, "{$data['product_group_id']}-{$colorVariant['product_number']}-{$sizeVariant['itemNumber']}");
|
||||
|
||||
if($variant)
|
||||
{
|
||||
$this->assignImages($variant, $colorVariant['images']);
|
||||
$this->assignAttributes($variant, [
|
||||
|
|
@ -368,7 +370,7 @@ class ProductRepository extends WProductRepository
|
|||
|
||||
}
|
||||
}
|
||||
elseif($variant = $this->createVariant($parentProduct, $colorVariant['product_number']))
|
||||
elseif($variant = $this->createVariant($parentProduct, "{$data['product_group_id']}-{$colorVariant['product_number']}"))
|
||||
{
|
||||
$this->assignImages($variant, $colorVariant['images']);
|
||||
$this->assignAttributes($variant, [
|
||||
|
|
@ -390,7 +392,7 @@ class ProductRepository extends WProductRepository
|
|||
$attribute = $this->attributeRepository->findOneByField('code', 'size');
|
||||
$parentProduct->super_attributes()->attach($attribute->id);
|
||||
foreach ($data['size_variants'] as $sizeVariant) {
|
||||
if($variant = $this->createVariant($parentProduct, $data['product_number'] . $sizeVariant['size'])){
|
||||
if($variant = $this->createVariant($parentProduct, "{$data['product_group_id']}-{$data['product_number']}-{$sizeVariant['itemNumber']}")){
|
||||
$this->assignImages($variant, $data['images']);
|
||||
$attributes = [
|
||||
'sku' => $variant->sku,
|
||||
|
|
@ -598,58 +600,30 @@ class ProductRepository extends WProductRepository
|
|||
]);
|
||||
}
|
||||
}
|
||||
private function assignAttributes($product, $attributes,$check_option_values = false){
|
||||
private function assignAttributes($product, $attributes){
|
||||
foreach($attributes as $code => $value){
|
||||
$attribute = $this->attributeRepository->findOneByField('code', $code);
|
||||
|
||||
if ($attribute->value_per_channel) {
|
||||
if ($attribute->value_per_locale) {
|
||||
foreach (core()->getAllChannels() as $channel) {
|
||||
foreach (core()->getAllLocales() as $locale) {
|
||||
$this->attributeValueRepository->create([
|
||||
'product_id' => $product->id,
|
||||
'attribute_id' => $attribute->id,
|
||||
'channel' => $channel->code,
|
||||
'locale' => $locale->code,
|
||||
'value' => $value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach (core()->getAllChannels() as $channel) {
|
||||
$this->attributeValueRepository->create([
|
||||
'product_id' => $product->id,
|
||||
'attribute_id' => $attribute->id,
|
||||
'channel' => $channel->code,
|
||||
'value' => $value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($attribute->value_per_locale) {
|
||||
foreach (core()->getAllLocales() as $locale) {
|
||||
$this->attributeValueRepository->create([
|
||||
'product_id' => $product->id,
|
||||
'attribute_id' => $attribute->id,
|
||||
'locale' => $locale->code,
|
||||
'value' => $value,
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
$attr = [
|
||||
'product_id' => $product->id,
|
||||
'attribute_id' => $attribute->id,
|
||||
'value' => $value,
|
||||
];
|
||||
$this->attributeValueRepository->create($attr);
|
||||
}catch (\Exception $e) {
|
||||
Log::error($e);
|
||||
Log::info($attr);
|
||||
}
|
||||
$attr = [
|
||||
'product_id' => $product->id,
|
||||
'attribute_id' => $attribute->id,
|
||||
'value' => $value
|
||||
];
|
||||
|
||||
}
|
||||
if($attribute->value_per_channel){
|
||||
$attr['channel'] = config('app.channel');
|
||||
}
|
||||
|
||||
if ($attribute->value_per_locale){
|
||||
foreach (core()->getAllLocales() as $locale){
|
||||
$attr['locale'] = $locale->code;
|
||||
$this->attributeValueRepository->create($attr);
|
||||
}
|
||||
|
||||
}else{
|
||||
$this->attributeValueRepository->create($attr);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue