Skip to content

Commit

Permalink
[FIX] Disabled oldPrice issue, #1118
Browse files Browse the repository at this point in the history
  • Loading branch information
SamBrishes committed May 1, 2024
1 parent b7e7f2b commit a84bcb7
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
.phpunit.result.cache
.vscode
composer.lock
docs/.vitepress/cache
docs/.vitepress/dist
src/docs/.vitepress/cache
src/docs/.vitepress/dist
nbproject
node_modules
vendor
4 changes: 2 additions & 2 deletions classes/traits/PriceAccessors.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

<?php declare(strict_types=1);

namespace OFFLINE\Mall\Classes\Traits;

Expand All @@ -15,6 +14,7 @@
trait PriceAccessors
{
use NullPrice;

/**
* @var Money
*/
Expand Down
76 changes: 57 additions & 19 deletions classes/traits/ProductPriceAccessors.php
Original file line number Diff line number Diff line change
@@ -1,70 +1,93 @@
<?php

<?php declare(strict_types=1);

namespace OFFLINE\Mall\Classes\Traits;

use October\Rain\Database\Collection;
use OFFLINE\Mall\Models\Currency;
use OFFLINE\Mall\Models\CustomerGroup;
use OFFLINE\Mall\Models\PriceCategory;

trait ProductPriceAccessors
{
/**
* Undocumented function
* @param CustomerGroup $group
* @param mixed $currency
* @return mixed
*/
public function groupPrice(CustomerGroup $group, $currency)
{
$currency = Currency::resolve($currency);

$prices = $this->customer_group_prices;

$filter = function ($query) use ($group) {
return $query->where('customer_group_id', $group->id);
};

$price = $this->withFilter($filter, $prices->where('currency_id', $currency->id))->first();

return $price
?? $this->nullPrice(
if ($price) {
return $price;
} else {
return $this->nullPrice(
$currency,
$this->withFilter($filter, $prices),
'customer_group_prices',
$filter
);
}
}

/**
* Undocumented function
* @param int|PriceCategory $category
* @param mixed $currency
* @return mixed
*/
public function additionalPrice($category, $currency = null)
{
$currency = Currency::resolve($currency);

$prices = $this->additional_prices;

if ($category instanceof PriceCategory) {
$category = $category->id;
}

$currency = Currency::resolve($currency);
$prices = $this->additional_prices;
$filter = function ($query) use ($category) {
return $query->where('price_category_id', $category);
};

$query = $this->withFilter($filter, $prices->where('currency_id', $currency->id));

return $query->first()
?? $this->nullPrice(
$price = $this->withFilter($filter, $prices->where('currency_id', $currency->id))->first();
if ($price) {
return $price;
} else {
return $this->nullPrice(
$currency,
$this->withFilter($filter, $prices),
'additional_prices',
$filter
);
}
}

/**
* Undocumented function
* @deprecated 3.2.2 - The oldPrice category has been made optional.
* @return mixed
*/
public function oldPriceRelations()
{
$oldPrice = PriceCategory::where('code', 'old_price')->first();
if ($oldPrice) {
return $this->additional_prices->where('price_category_id', $oldPrice->id);
} else {
return [];
return new Collection();
}
}

/**
* Undocumented function
* @deprecated 3.2.2 - The oldPrice category has been made optional.
* @param mixed $currency
* @return mixed
*/
public function oldPrice($currency = null)
{
$oldPrice = PriceCategory::where('code', 'old_price')->first();
Expand All @@ -74,14 +97,29 @@ public function oldPrice($currency = null)
return null;
}
}


/**
* Undocumented function
* @deprecated 3.2.2 - The oldPrice category has been made optional.
* @return mixed
*/
public function getOldPriceAttribute()
{
return $this->mapCurrencyPrices($this->oldPriceRelations());
}

public function getOnSaleAttribute()
/**
* Undocumented function
* @deprecated 3.2.2 - The oldPrice category has been made optional.
* @return boolean
*/
public function getOnSaleAttribute(): bool
{
return $this->old_price->count() > 0;
$price = $this->old_price;
if ($price && $price->count() > 0) {
return true;
} else {
return false;
}
}
}
5 changes: 4 additions & 1 deletion updates/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -560,4 +560,7 @@ v3.2.0:
- 030_07-alter_offline_mall_order_states.php
- 030_08-create_offline_mall_product_file_variant_table.php
v3.2.1:
- 'Fix Release Number'
- 'Fix Release Number'
v3.2.2:
- 'Minor Bugfix'
- 'Fixed mapWithKeys() on array call when oldPrice has been disabled, thanks to @dathwa (#1118).'

0 comments on commit a84bcb7

Please sign in to comment.