From dc347664d144ef7269e7137909f71cb364375488 Mon Sep 17 00:00:00 2001 From: merdan Date: Thu, 7 Apr 2022 18:23:20 +0500 Subject: [PATCH] fix mix --- .../Shop/src/Repositories/ProductRepository.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/Sarga/Shop/src/Repositories/ProductRepository.php b/packages/Sarga/Shop/src/Repositories/ProductRepository.php index 8689d9ee7..dab88b6ce 100644 --- a/packages/Sarga/Shop/src/Repositories/ProductRepository.php +++ b/packages/Sarga/Shop/src/Repositories/ProductRepository.php @@ -299,9 +299,10 @@ class ProductRepository extends WProductRepository } //create product $parentProduct = $this->getModel()->create($product); - $this->assignAttributes($parentProduct, [ + $originalPrice = Arr::get($data, 'price.discountedPrice.value'); + $discountedPrice = Arr::get($data, 'price.discountedPrice.value'); + $main_attributes = [ 'sku' => $parentProduct->sku, - 'price' => Arr::get($data, 'price.discountedPrice.value'), 'name' => $data['name'], 'weight' => $data['weight'] ?? 0.45, 'source' => $data['url_key'], @@ -310,7 +311,17 @@ class ProductRepository extends WProductRepository 'url_key' => $parentProduct->sku, // 'short_description' => $data['url_key'], 'description' => implode(array_map(fn($value): string => '

' . $value['description'] . '

', $data['descriptions'])) - ]); + ]; + + if($originalPrice > $discountedPrice){ + $main_attributes['price'] = $originalPrice; + $main_attributes['special_price'] = $discountedPrice; + } + else{ + $main_attributes['price'] = $discountedPrice; + } + + $this->assignAttributes($parentProduct, $main_attributes); if (!empty($data['images'])) { $this->assignImages($parentProduct, $data['images']);