diff --git a/packages/Webkul/Marketing/src/Providers/MarketingServiceProvider.php b/packages/Webkul/Marketing/src/Providers/MarketingServiceProvider.php index ba2ffaf37..d5f19b8ea 100644 --- a/packages/Webkul/Marketing/src/Providers/MarketingServiceProvider.php +++ b/packages/Webkul/Marketing/src/Providers/MarketingServiceProvider.php @@ -4,6 +4,7 @@ namespace Webkul\Marketing\Providers; use Illuminate\Support\ServiceProvider; use Webkul\Marketing\Console\Commands\EmailsCommand; +use Illuminate\Console\Scheduling\Schedule; class MarketingServiceProvider extends ServiceProvider { @@ -17,6 +18,10 @@ class MarketingServiceProvider extends ServiceProvider $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); $this->loadRoutesFrom(__DIR__ . '/../Http/routes.php'); + + $this->callAfterResolving(Schedule::class, function (Schedule $schedule) { + $schedule->command('campaign:process')->daily(); + }); } /** diff --git a/packages/Webkul/Product/src/Helpers/ConfigurableOption.php b/packages/Webkul/Product/src/Helpers/ConfigurableOption.php index 004ede9e5..2ce0b6963 100755 --- a/packages/Webkul/Product/src/Helpers/ConfigurableOption.php +++ b/packages/Webkul/Product/src/Helpers/ConfigurableOption.php @@ -62,8 +62,8 @@ class ConfigurableOption extends AbstractProduct 'attributes' => $this->getAttributesData($product, $options), 'index' => isset($options['index']) ? $options['index'] : [], 'regular_price' => [ - 'formated_price' => core()->currency($product->getTypeInstance()->getMinimalPrice()), - 'price' => $product->getTypeInstance()->getMinimalPrice(), + 'formated_price' => $product->getTypeInstance()->haveOffer() ? core()->currency($product->getTypeInstance()->getOfferPrice()) : core()->currency($product->getTypeInstance()->getMinimalPrice()), + 'price' => $product->getTypeInstance()->haveOffer() ? $product->getTypeInstance()->getOfferPrice() : $product->getTypeInstance()->getMinimalPrice(), ], 'variant_prices' => $this->getVariantPrices($product), 'variant_images' => $this->getVariantImages($product), diff --git a/packages/Webkul/Product/src/Type/AbstractType.php b/packages/Webkul/Product/src/Type/AbstractType.php index ba021e53e..8383e15b9 100644 --- a/packages/Webkul/Product/src/Type/AbstractType.php +++ b/packages/Webkul/Product/src/Type/AbstractType.php @@ -958,7 +958,7 @@ abstract class AbstractType if ($haveOffers) { foreach ($customerGroupPrices as $key => $customerGroupPrice) { - if ($key > 0) { + if ($customerGroupPrice && $customerGroupPrice->qty > 1) { array_push($offerLines, $this->getOfferLines($customerGroupPrice)); } } @@ -984,7 +984,7 @@ abstract class AbstractType public function getOfferLines($customerGroupPrice) { $price = $this->getCustomerGroupPrice($this->product, $customerGroupPrice->qty); - $discount = (($this->product->price - $price) * 100) / ($this->product->price); + $discount = number_format((($this->product->price - $price) * 100) / ($this->product->price), 2); $offerLines = trans('shop::app.products.offers', ['qty' => $customerGroupPrice->qty, 'price' => core()->currency($price), 'discount' => $discount]); diff --git a/packages/Webkul/Product/src/Type/Configurable.php b/packages/Webkul/Product/src/Type/Configurable.php index 7f05f41ed..2f06bde6a 100644 --- a/packages/Webkul/Product/src/Type/Configurable.php +++ b/packages/Webkul/Product/src/Type/Configurable.php @@ -355,7 +355,7 @@ class Configurable extends AbstractType */ public function getMinimalPrice($qty = null) { - $minPrices = $rulePrices = $customerGroupPrices = []; + $minPrices = []; /* method is calling many time so using variable */ $tablePrefix = DB::getTablePrefix(); @@ -373,6 +373,21 @@ class Configurable extends AbstractType $minPrices[] = $price->min_price; } + if (empty($minPrices)) { + return 0; + } + + return min($minPrices); + } + + /** + * Get product offer price + * + * @return float + */ + public function getOfferPrice() { + $rulePrices = $customerGroupPrices = []; + foreach ($this->product->variants as $variant) { $rulePrice = app('Webkul\CatalogRule\Helpers\CatalogRuleProductPrice')->getRulePrice($variant); @@ -383,11 +398,29 @@ class Configurable extends AbstractType $customerGroupPrices[] = $this->getCustomerGroupPrice($variant, 1); } - if (empty($minPrices)) { - return 0; + if ($rulePrices || $customerGroupPrices) { + return min(array_merge($rulePrices, $customerGroupPrices)); } - return min(array_merge(array_merge($minPrices, $rulePrices), $customerGroupPrices)); + return []; + } + + /** + * Check for offer + * + * @return bool + */ + public function haveOffer() { + $haveOffer = false; + + $offerPrice = $this->getOfferPrice(); + $minPrice = $this->getMinimalPrice(); + + if ($offerPrice < $minPrice) { + $haveOffer = true; + } + + return $haveOffer; } /** @@ -415,9 +448,16 @@ class Configurable extends AbstractType */ public function getPriceHtml() { - return '' . trans('shop::app.products.price-label') . '' + if ($this->haveOffer()) { + return '