简体   繁体   English

将价格范围值与产品表的两列进行比较,产品正常价格和产品销售价格

[英]Compare price range value to two columns to product table, product regular price and product sale price

I have two columns in table name as product regular price and product sale price.我在表名中有两列,分别是产品正常价格和产品销售价格。 I have to search min price products against a price range given by the user.我必须根据用户给出的价格范围搜索最低价格产品。 It is easy to search min price from a single column but from both columns, it seems very difficult.从单列中搜索最低价格很容易,但从两列中搜索似乎非常困难。

$products = $products->whereBetween(['ecommerce_sku.regular_price','ecommerce_sku.sale_price'], [$minPrice, $maxPrice]);

You can separate regular price and sales price.您可以将正常价格和销售价格分开。

$products = $products
->whereBetween('ecommerce_sku.sale_price', [$minPrice, $maxPrice])
->whereBetween('ecommerce_sku.regular_price', [$minPrice, $maxPrice]); 

Raw query:原始查询:

$string = '(ecommerce_sku.sale_price between "'.$minPrice.'" and "'.$maxPrice.'") AND (ecommerce_sku.regular_price between "'.$minPrice.'" and "'.$maxPrice.'")'
$products = $products->whereRaw($string);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 产品正常价格优惠券折扣(非促销价) - Coupon discount on product regular price (not sale price) 如果销售价格等于零,则仅在 Woocommerce 中显示常规产品价格 - If sale price is equal to zero show only regular product price in Woocommerce 当产品的正常价格和销售价格相同时,我想在产品页面上显示可变产品的销售价格。我该怎么做? - I want to display the sale price of variable product on the product page when the regular price and sale price of product are same.How can I do this? 以编程方式将销售价格添加到产品变体 - Add sale price programmatically to product variations 在 WooCommerce 3 中以编程方式设置产品销售价格 - Set product sale price programmatically in WooCommerce 3 在 WooCommerce 结帐问题中显示产品销售价格 - Display product sale price in WooCommerce checkout issues Woocommerce 通过正确的产品分类更改销售价格 - Woocommerce change sale price with correct product sorting 如何删除 Woocommerce 中特定产品的销售价格? - How to remove sale price on specific product in Woocommerce? 使用范围内的价格过滤产品 - Filter product using price in range 如果值为 0 wooCommerce 包括产品变化,有没有办法制定销售价格 null - Is there a way to make a sale price null if the value is 0 wooCommerce including product variations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM