Add customer product fixed price overrides
This commit is contained in:
@@ -981,6 +981,31 @@ class users_o extends db
|
||||
return $discount_percentage === null ? 0 : (int)$discount_percentage;
|
||||
}
|
||||
|
||||
public function getProductFixedPrice(int $product_id): ?int
|
||||
{
|
||||
self::requireSelected();
|
||||
return $this->price_overrides->setUser($this->id)->getFixedPrice(false, $product_id);
|
||||
}
|
||||
|
||||
public function applyProductCustomerPricing(int $product_id, int $base_price, bool $use_final_price_discount_calculation = true): int
|
||||
{
|
||||
self::requireSelected();
|
||||
|
||||
$fixed_price = $this->getProductFixedPrice($product_id);
|
||||
if ($fixed_price !== null) {
|
||||
return $fixed_price;
|
||||
}
|
||||
|
||||
$discount_percentage = $use_final_price_discount_calculation
|
||||
? (int)$this->getProductDiscountPercentage($product_id)
|
||||
: (int)$this->getCustomPrice($product_id, false);
|
||||
if ($discount_percentage <= 0) {
|
||||
return $base_price;
|
||||
}
|
||||
|
||||
return (int)round($base_price * (1 - ($discount_percentage / 100)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@@ -1183,15 +1208,16 @@ class users_o extends db
|
||||
* @param int $object_id The ID of the object
|
||||
* @param int $discount_percentage The discount percentage
|
||||
* @param bool $is_category If the object is a category
|
||||
* @param int|null $fixed_price The fixed product price, when set
|
||||
* @return void
|
||||
*/
|
||||
public function setCustomPrice(int $user_id, int|string $object_id, int $discount_percentage, bool $is_category = false): void
|
||||
public function setCustomPrice(int $user_id, int|string $object_id, int $discount_percentage, bool $is_category = false, ?int $fixed_price = null): void
|
||||
{
|
||||
$this->id = $user_id;
|
||||
// Get the user object properties
|
||||
$this->getObjectProperties();
|
||||
// Set the custom price (key = 'custom_price')
|
||||
$this->price_overrides->setUser($this->id)->setPrice($is_category, $object_id, $discount_percentage);
|
||||
$this->price_overrides->setUser($this->id)->setPrice($is_category, $object_id, $discount_percentage, $fixed_price);
|
||||
}
|
||||
|
||||
public function syncAllUsersEconomicCustomerDetails(): void
|
||||
|
||||
Reference in New Issue
Block a user