| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Description of PriceFormula |
| 5 |
* |
| 6 |
* @author Ali2Woo Team |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace AliNext_Lite;; |
| 10 |
|
| 11 |
class PriceFormula |
| 12 |
{ |
| 13 |
public const TYPE_ALL = 'all'; |
| 14 |
public const TYPE_PRICE = 'price'; |
| 15 |
public const TYPE_REGULAR_PRICE = 'regular_price'; |
| 16 |
|
| 17 |
|
| 18 |
public const FIELD_ID = 'id'; |
| 19 |
public const FIELD_CATEGORY = 'category'; |
| 20 |
public const FIELD_CATEGORY_IDS = 'category_ids'; |
| 21 |
public const FIELD_CATEGORY_NAME = 'category_name'; |
| 22 |
public const FIELD_MIN_PRICE = 'min_price'; |
| 23 |
public const FIELD_MAX_PRICE = 'max_price'; |
| 24 |
public const FIELD_SIGN = 'sign'; |
| 25 |
public const FIELD_VALUE = 'value'; |
| 26 |
public const FIELD_COMPARED_SIGN = 'compared_sign'; |
| 27 |
public const FIELD_COMPARED_VALUE = 'compared_value'; |
| 28 |
|
| 29 |
|
| 30 |
public int $id = 0; |
| 31 |
public ?int $category = null; |
| 32 |
public ?array $categoryIds = null; |
| 33 |
public ?string $category_name = null; |
| 34 |
public ?float $min_price = null; |
| 35 |
public ?float $max_price = null; |
| 36 |
public string $sign = '*'; |
| 37 |
public ?float $value = null; |
| 38 |
public string $compared_sign = '*'; |
| 39 |
public ?float $compared_value = null; |
| 40 |
|
| 41 |
public static function pricing_rules_types() |
| 42 |
{ |
| 43 |
$helpUrl = esc_url( 'https://help.ali2woo.com/codex/pricing-markup-formula/'); |
| 44 |
$helpUrlText = esc_html__('this article', 'ali2woo'); |
| 45 |
$salePriceText = esc_html__('sale price', 'ali2woo'); |
| 46 |
$regularPriceText = esc_html__('regular price', 'ali2woo'); |
| 47 |
|
| 48 |
$salePriceAndDiscountText = sprintf( |
| 49 |
esc_html__( |
| 50 |
'AliNext (Lite version) gets your %s by applying a pricing formula to the AliExpress sale price. Your %s is calculated using the %s part of the formula.', |
| 51 |
'ali2woo'), |
| 52 |
sprintf( |
| 53 |
'<strong>%s</strong> ', |
| 54 |
$salePriceText |
| 55 |
), |
| 56 |
sprintf( |
| 57 |
'<strong>%s</strong>', |
| 58 |
$regularPriceText |
| 59 |
), |
| 60 |
sprintf( |
| 61 |
'<i>%s</i>', |
| 62 |
$regularPriceText |
| 63 |
) |
| 64 |
); |
| 65 |
|
| 66 |
$salePriceAndDiscountText .= '<br/>' . sprintf( |
| 67 |
esc_html__('If you disable that part, the %s is formed from your calculated sale price increased by the original AliExpress discount.', 'ali2woo'), |
| 68 |
sprintf( |
| 69 |
'<strong>%s</strong> ', |
| 70 |
$regularPriceText |
| 71 |
) |
| 72 |
); |
| 73 |
|
| 74 |
$salePriceAndDiscountText .= '<br/>' . sprintf( |
| 75 |
esc_html__('To learn more check out %s', 'ali2woo'), |
| 76 |
/* translators: %1$s is replaced with a link to help resource, %1$s is replaced with a link text */ |
| 77 |
sprintf( |
| 78 |
'<a href="%1$s">%2$s</a>', |
| 79 |
$helpUrl, |
| 80 |
$helpUrlText |
| 81 |
), |
| 82 |
); |
| 83 |
|
| 84 |
$salePriceText = sprintf( |
| 85 |
esc_html__('Your pricing formula is applied to the AliExpress sale price. To learn more check out %s', 'ali2woo'), |
| 86 |
/* translators: %1$s is replaced with a link to help resource, %1$s is replaced with a link text */ |
| 87 |
sprintf( |
| 88 |
'<a href="%1$s">%2$s</a>', |
| 89 |
$helpUrl, |
| 90 |
$helpUrlText |
| 91 |
), |
| 92 |
); |
| 93 |
|
| 94 |
$regularPriceText = sprintf( |
| 95 |
esc_html__('Your pricing formula is applied to the AliExpress regular price. To learn more check out %s', 'ali2woo'), |
| 96 |
/* translators: %1$s is replaced with a link to help resource, %1$s is replaced with a link text */ |
| 97 |
sprintf( |
| 98 |
'<a href="%1$s">%2$s</a>', |
| 99 |
$helpUrl, |
| 100 |
$helpUrlText |
| 101 |
), |
| 102 |
); |
| 103 |
|
| 104 |
return [ |
| 105 |
PriceFormulaService::SALE_PRICE_AND_DISCOUNT => [ |
| 106 |
'value' => PriceFormulaService::SALE_PRICE_AND_DISCOUNT, |
| 107 |
'name' => esc_html__('Use sale price and discount', 'ali2woo'), |
| 108 |
'description' => $salePriceAndDiscountText, |
| 109 |
], |
| 110 |
PriceFormulaService::SALE_PRICE_AS_BASE => [ |
| 111 |
'value' => PriceFormulaService::SALE_PRICE_AS_BASE, |
| 112 |
'name' => esc_html__('Use sale price as base', 'ali2woo'), |
| 113 |
'description' => $salePriceText, |
| 114 |
], |
| 115 |
PriceFormulaService::REGULAR_PRICE_AS_BASE => [ |
| 116 |
'value' => PriceFormulaService::REGULAR_PRICE_AS_BASE , |
| 117 |
'name' => esc_html__('Use regular price as base', 'ali2woo'), |
| 118 |
'description' => $regularPriceText, |
| 119 |
], |
| 120 |
]; |
| 121 |
} |
| 122 |
|
| 123 |
public function __construct(?array $data = null) |
| 124 |
{ |
| 125 |
//todo: remove this and use setter and getter instead |
| 126 |
if ($data) { |
| 127 |
foreach ($data as $field => $value) { |
| 128 |
if (property_exists(get_class($this), $field)) { |
| 129 |
$this->$field = esc_attr($value); |
| 130 |
} |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
public function getId(): int |
| 136 |
{ |
| 137 |
return $this->id; |
| 138 |
} |
| 139 |
|
| 140 |
public function setId(int $id): self |
| 141 |
{ |
| 142 |
$this->id = $id; |
| 143 |
|
| 144 |
return $this; |
| 145 |
} |
| 146 |
|
| 147 |
public function getCategory(): ?int |
| 148 |
{ |
| 149 |
return $this->category; |
| 150 |
} |
| 151 |
|
| 152 |
public function setCategory(?int $category): self |
| 153 |
{ |
| 154 |
$this->category = $category; |
| 155 |
|
| 156 |
return $this; |
| 157 |
} |
| 158 |
|
| 159 |
public function getCategoryName(): ?string |
| 160 |
{ |
| 161 |
return $this->category_name; |
| 162 |
} |
| 163 |
|
| 164 |
public function setCategoryName(?string $categoryName): self |
| 165 |
{ |
| 166 |
$this->category_name = $categoryName; |
| 167 |
|
| 168 |
return $this; |
| 169 |
} |
| 170 |
|
| 171 |
public function getMinPrice(): ?float |
| 172 |
{ |
| 173 |
return $this->min_price; |
| 174 |
} |
| 175 |
|
| 176 |
public function setMinPrice(?float $minPrice): self |
| 177 |
{ |
| 178 |
$this->min_price = $minPrice; |
| 179 |
|
| 180 |
return $this; |
| 181 |
} |
| 182 |
|
| 183 |
public function getMaxPrice(): ?float |
| 184 |
{ |
| 185 |
return $this->max_price; |
| 186 |
} |
| 187 |
|
| 188 |
public function setMaxPrice(?float $maxPrice): self |
| 189 |
{ |
| 190 |
$this->max_price = $maxPrice; |
| 191 |
|
| 192 |
return $this; |
| 193 |
} |
| 194 |
|
| 195 |
public function getValue(): ?float |
| 196 |
{ |
| 197 |
return $this->value; |
| 198 |
} |
| 199 |
|
| 200 |
public function setValue(?float $value): self |
| 201 |
{ |
| 202 |
$this->value = $value; |
| 203 |
|
| 204 |
return $this; |
| 205 |
} |
| 206 |
|
| 207 |
public function getComparedValue(): ?float |
| 208 |
{ |
| 209 |
return $this->compared_value; |
| 210 |
} |
| 211 |
|
| 212 |
public function setComparedValue(?float $comparedValue): self |
| 213 |
{ |
| 214 |
$this->compared_value = $comparedValue; |
| 215 |
|
| 216 |
return $this; |
| 217 |
} |
| 218 |
|
| 219 |
public function getSign(): string |
| 220 |
{ |
| 221 |
return $this->sign; |
| 222 |
} |
| 223 |
|
| 224 |
public function setSign(string $sign): self |
| 225 |
{ |
| 226 |
$this->sign = $sign; |
| 227 |
|
| 228 |
return $this; |
| 229 |
} |
| 230 |
|
| 231 |
public function getComparedSign(): string |
| 232 |
{ |
| 233 |
return $this->compared_sign; |
| 234 |
} |
| 235 |
|
| 236 |
public function setComparedSign(string $comparedSign): self |
| 237 |
{ |
| 238 |
$this->compared_sign = $comparedSign; |
| 239 |
|
| 240 |
return $this; |
| 241 |
} |
| 242 |
|
| 243 |
public function getCategoryIds(): ?array |
| 244 |
{ |
| 245 |
return $this->categoryIds; |
| 246 |
} |
| 247 |
|
| 248 |
public function setCategoryIds(?array $categoryIds): self |
| 249 |
{ |
| 250 |
$this->categoryIds = $categoryIds; |
| 251 |
|
| 252 |
return $this; |
| 253 |
} |
| 254 |
|
| 255 |
public function toArray(): array |
| 256 |
{ |
| 257 |
return [ |
| 258 |
self::FIELD_ID => $this->getId(), |
| 259 |
self::FIELD_CATEGORY => $this->getCategory(), |
| 260 |
self::FIELD_CATEGORY_IDS => $this->getCategoryIds(), |
| 261 |
self::FIELD_CATEGORY_NAME => $this->getCategoryName(), |
| 262 |
self::FIELD_MIN_PRICE => $this->getMinPrice(), |
| 263 |
self::FIELD_MAX_PRICE => $this->getMaxPrice(), |
| 264 |
self::FIELD_SIGN => $this->getSign(), |
| 265 |
self::FIELD_VALUE => $this->getValue(), |
| 266 |
self::FIELD_COMPARED_SIGN => $this->getComparedSign(), |
| 267 |
self::FIELD_COMPARED_VALUE => $this->getComparedValue(), |
| 268 |
]; |
| 269 |
} |
| 270 |
|
| 271 |
} |
| 272 |
|