PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.9.2
ووسلام – همگام سازی ووکامرس و باسلام v1.9.2
1.10.19 1.10.20 1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 1.8.6 All 53 releases
sync-basalam / includes / Services / Products / Discount / SimpleProductDiscount.php

SimpleProductDiscount.php in ووسلام – همگام سازی ووکامرس و باسلام 1.9.2, at includes/Services/Products/Discount/SimpleProductDiscount.php

40 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SyncBasalam\Services\Products\Discount;
4
5 use SyncBasalam\Utilities\ProductMetaKey;
6
7 defined('ABSPATH') || exit;
8
9 class SimpleProductDiscount implements DiscountInterface
10 {
11 private $discountService;
12
13 public function __construct(DiscountManager $discountService)
14 {
15 $this->discountService = $discountService;
16 }
17
18 public function apply($product): void
19 {
20 $basalam_id = get_post_meta($product->get_id(), ProductMetaKey::basalamProductId(), true);
21 if (!$basalam_id) return;
22
23 $regular = $product->get_regular_price();
24 $sale = $product->get_sale_price();
25
26 if (!$regular || !$sale) return;
27
28 $discount = $this->discountService->calculateDiscountPercent($regular, $sale);
29 $this->discountService->apply($discount, [$basalam_id], null, null);
30 }
31
32 public function remove($product): void
33 {
34 $basalam_id = get_post_meta($product->get_id(), ProductMetaKey::basalamProductId(), true);
35 if ($basalam_id) {
36 $this->discountService->remove([$basalam_id], null);
37 }
38 }
39 }
40