Catalog rules working for all product types

This commit is contained in:
jitendra 2020-01-06 13:00:01 +05:30
parent 7aba45486f
commit 77563c57f1
3 changed files with 32 additions and 10 deletions

View File

@ -124,7 +124,6 @@ class CatalogRuleProduct
->addSelect('products.*')
->leftJoin('product_flat', 'products.id', '=', 'product_flat.product_id')
->leftJoin('channels', 'product_flat.channel', '=', 'channels.code')
->where('product_flat.status', 1)
->whereIn('channels.id', $rule->channels()->pluck('id')->toArray());
if ($product)
@ -209,17 +208,16 @@ class CatalogRuleProduct
$results = $this->catalogRuleProductRepository->scopeQuery(function($query) use($product) {
$qb = $query->distinct()
->select('catalog_rule_products.*')
->leftJoin('product_flat', 'catalog_rule_products.product_id', '=', 'product_flat.product_id')
->where('product_flat.status', 1)
->addSelect('product_flat.price')
->leftJoin('products', 'catalog_rule_products.product_id', '=', 'products.id')
->orderBy('channel_id', 'asc')
->orderBy('customer_group_id', 'asc')
->orderBy('product_id', 'asc')
->orderBy('sort_order', 'asc')
->orderBy('catalog_rule_id', 'asc');
if ($product) {
$qb = $this->addAttributeToSelect('price', $qb);
if ($product) {
if (! $product->getTypeInstance()->priceRuleCanBeApplied())
return $qb;

View File

@ -487,12 +487,26 @@ abstract class AbstractType
*/
public function haveSpecialPrice()
{
if (is_null($this->product->special_price) || ! (float) $this->product->special_price) {
return false;
}
$rulePrice = app('Webkul\CatalogRule\Helpers\CatalogRuleProductPrice')->getRulePrice($this->product);
if (core()->isChannelDateInInterval($this->product->special_price_from, $this->product->special_price_to)) {
return true;
if ((is_null($this->product->special_price) || ! (float) $this->product->special_price) && ! $rulePrice)
return false;
if (! (float) $this->product->special_price) {
if ($rulePrice) {
$this->product->special_price = $rulePrice->price;
return true;
}
} else {
if ($rulePrice && $rulePrice->price <= $this->product->special_price) {
$this->product->special_price = $rulePrice->price;
return true;
} else {
if (core()->isChannelDateInInterval($this->product->special_price_from, $this->product->special_price_to))
return true;
}
}
return false;

View File

@ -114,6 +114,16 @@ class Grouped extends AbstractType
return array_unique($this->product->grouped_products()->pluck('product_id')->toArray());
}
/**
* Check if catalog rule can be applied
*
* @return bool
*/
public function priceRuleCanBeApplied()
{
return false;
}
/**
* Get product minimal price
*