active brands

This commit is contained in:
merdan 2022-04-10 17:00:58 +05:00
parent 8b3ae7ee5b
commit 92809547fa
4 changed files with 75 additions and 24 deletions

View File

@ -76,4 +76,18 @@ class IntegrationController extends Controller
}
public function update(){
try {
$data = json_decode(request()->getContent(),true);
}
catch (\Exception $e){
Log::error($e->getMessage());
return response()->json(['errors'=>$e->getMessage()],400);
}
if(! $product = $this->productRepository->findOneByField('sku',$data['sku'])){
return response()->json(['success'=> false,'message' => 'product not found'],400);
}
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace Sarga\API\Http\Resources\Catalog;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Storage;
class VendorCategory extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'display_mode' => $this->display_mode,
'image_url' => $this->image_url,
'children' => Category::collection($this->children),
];
}
}

View File

@ -126,6 +126,7 @@ Route::group(['prefix' => 'api'], function () {
Route::group(['prefix' => 'scrap','middleware' =>['scrap']], function (){
Route::put('upload',[IntegrationController::class,'bulk_upload']);
Route::put('create',[IntegrationController::class,'create']);
Route::put('update',[IntegrationController::class,'update']);
});
});

View File

@ -266,6 +266,7 @@ class ProductRepository extends WProductRepository
return $results;
}
public function create($data){
$time_start = microtime(true);
@ -346,25 +347,28 @@ 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) {
$variant = $this->createVariant($parentProduct, $colorVariant['product_number'] . $sizeVariant['size']);
if($variant = $this->createVariant($parentProduct, $colorVariant['product_number'] . $sizeVariant['size']))
{
$this->assignImages($variant, $colorVariant['images']);
$this->assignAttributes($variant, [
'sku' => $variant->sku,
'color' => $this->getAttributeOptionId('color', $colorVariant['color']),
'name' => $colorVariant['name'],
'size' => $this->getAttributeOptionId('size', $sizeVariant['size']),
'price' => $sizeVariant['price'],
'weight' => $colorVariant['weight'] ?? 0.45,
'status' => 1,
'visible_individually' => 1,
'url_key' => $variant->sku,
'source' => $colorVariant['url_key'],
'description' => $description
]);
}
$this->assignImages($variant, $colorVariant['images']);
$this->assignAttributes($variant, [
'sku' => $variant->sku,
'color' => $this->getAttributeOptionId('color', $colorVariant['color']),
'name' => $colorVariant['name'],
'size' => $this->getAttributeOptionId('size', $sizeVariant['size']),
'price' => $sizeVariant['price'],
'weight' => $colorVariant['weight'] ?? 0.45,
'status' => 1,
'visible_individually' => 1,
'url_key' => $variant->sku,
'source' => $colorVariant['url_key'],
'description' => $description
]);
}
} else {
$variant = $this->createVariant($parentProduct, $colorVariant['product_number']);
}
elseif($variant = $this->createVariant($parentProduct, $colorVariant['product_number']))
{
$this->assignImages($variant, $colorVariant['images']);
$this->assignAttributes($variant, [
'sku' => $variant->sku,
@ -648,13 +652,19 @@ class ProductRepository extends WProductRepository
}
private function createVariant($product, $sku){
return $this->getModel()->create([
'parent_id' => $product->id,
'type' => 'simple',
'attribute_family_id' => $product->attribute_family_id,
'sku' => $sku,
'brand_id' => $product->brand_id
]);
try{
return $this->getModel()->create([
'parent_id' => $product->id,
'type' => 'simple',
'attribute_family_id' => $product->attribute_family_id,
'sku' => $sku,
'brand_id' => $product->brand_id
]);
}
catch(\Exception $ex){
return false;
}
}