discount filter

This commit is contained in:
merdan 2022-05-14 18:40:38 +05:00
parent 54636be4e0
commit fb60a65d93
3 changed files with 34 additions and 22 deletions

View File

@ -8,7 +8,7 @@ use Sarga\Shop\Repositories\AttributeOptionRepository;
class AttributeOptions extends \Webkul\RestApi\Http\Controllers\V1\Shop\ResourceController
{
protected $requestException = ['page', 'limit', 'pagination', 'sort', 'order', 'token','locale','search'];
protected $requestException = ['page', 'limit', 'pagination', 'sort', 'order', 'token','locale','search','category'];
/**
* Repository class name.
*
@ -43,20 +43,26 @@ class AttributeOptions extends \Webkul\RestApi\Http\Controllers\V1\Shop\Resource
$query = $this->getRepositoryInstance()->scopeQuery(function ($query) use ($request) {
foreach ($request->except($this->requestException) as $input => $value) {
$query = $query->whereIn($input, array_map('trim', explode(',', $value)));
$query->whereIn($input, array_map('trim', explode(',', $value)));
}
if($key = $request->input('search')){
$query = $query->where('admin_name','like', '%'.$key.'%');
$query->where('admin_name','like', '%'.$key.'%');
//todo search in translations
}
if ($sort = $request->input('sort')) {
$query = $query->orderBy($sort, $request->input('order') ?? 'desc');
$query->orderBy($sort, $request->input('order') ?? 'desc');
} else {
$query = $query->orderBy('id', 'desc');
$query->orderBy('id', 'desc');
}
if($category = $request->input('category')){
$query->join('product_attribute_values','product_attribute_values.integer_value','=','attribute_options.id')
->join('product_categories','product_categories.product_id','=','product_attribute_values.product_id')
->where('product_attribute_values.attribute_id','attribute_options.attribute_id')
->where('product_categories.category_id',$category);
}
return $query;
});

View File

@ -114,17 +114,17 @@ class ProductRepository extends WProductRepository
$qb->where('product_flat.visible_individually', 1);
}
if (isset($params['search'])) {
$qb->where('product_flat.name', 'like', '%' . urldecode($params['search']) . '%');
}
if (isset($params['name'])) {
$qb->where('product_flat.name', 'like', '%' . urldecode($params['name']) . '%');
}
if (isset($params['url_key'])) {
$qb->where('product_flat.url_key', 'like', '%' . urldecode($params['url_key']) . '%');
}
// if (isset($params['search'])) {
// $qb->where('product_flat.name', 'like', '%' . urldecode($params['search']) . '%');
// }
//
// if (isset($params['name'])) {
// $qb->where('product_flat.name', 'like', '%' . urldecode($params['name']) . '%');
// }
//
// if (isset($params['url_key'])) {
// $qb->where('product_flat.url_key', 'like', '%' . urldecode($params['url_key']) . '%');
// }
# sort direction
$orderDirection = 'asc';
@ -322,7 +322,11 @@ class ProductRepository extends WProductRepository
private function calculatePrice($price){
$originalPrice = Arr::get($price, 'originalPrice.value');
$discountedPrice = Arr::get($price, 'discountedPrice.value');
$price_attributes = [];
$price_attributes = [
// 'min_price'=>$discountedPrice,'max_price'=>$originalPrice
];
if($originalPrice > $discountedPrice){
$price_attributes['price'] = $originalPrice;
$price_attributes['special_price'] = $discountedPrice;
@ -333,6 +337,7 @@ class ProductRepository extends WProductRepository
return $price_attributes;
}
public function createProduct($data){
$time_start = microtime(true);
@ -408,6 +413,7 @@ class ProductRepository extends WProductRepository
foreach ($data['color_variants'] as $colorVariant) {
$description = implode(array_map(fn($value): string => '<p>' . $value['description'] . '</p>', $colorVariant['descriptions']));
if (!empty($colorVariant['size_variants'])) {
$first = reset( $colorVariant['size_variants'] );
foreach ($colorVariant['size_variants'] as $sizeVariant) {
$variant = $this->createVariant($parentProduct, "{$data['product_group_id']}-{$colorVariant['product_number']}-{$sizeVariant['itemNumber']}");
@ -423,7 +429,7 @@ class ProductRepository extends WProductRepository
// 'price' => $sizeVariant['price'],
'weight' => $colorVariant['weight'] ?? 0.45,
'status' => 1,
'visible_individually' => 1,
'visible_individually' => $first == $sizeVariant,
'url_key' => $variant->sku,
'source' => $colorVariant['url_key'],
'description' => $description,
@ -475,8 +481,8 @@ class ProductRepository extends WProductRepository
'weight' => $data['weight'] ?? 0.45,
'status' => 1,
'featured'=> 0,
'new' => 1,
'visible_individually' => 1,
'new' => 0,
'visible_individually' => 0,
'url_key' => $variant->sku,
'source' => $data['url_key'],
'description' => $desc,

View File

@ -128,13 +128,13 @@ class ProductFlat
*/
public function afterProductCreatedUpdated($product)
{
$this->createFlat($product);
if (ProductType::hasVariants($product->type)) {
foreach ($product->variants()->get() as $variant) {
$this->createFlat($variant, $product);
}
}
$this->createFlat($product);
}
/**