PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.19
ووسلام – همگام سازی ووکامرس و باسلام v1.10.19
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 / VariableProductDiscount.php

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

44 lines 1.3 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 defined('ABSPATH') || exit;
6
7 class VariableProductDiscount implements DiscountInterface
8 {
9 private $discountService;
10
11 public function __construct(DiscountManager $discountService)
12 {
13 $this->discountService = $discountService;
14 }
15
16 public function apply($product): void
17 {
18 foreach ($product->get_children() as $variation_id) {
19 $variation = wc_get_product($variation_id);
20 if (!$variation) continue;
21 $basalam_id = get_post_meta($variation_id, 'sync_basalam_variation_id', true);
22 if (!$basalam_id) continue;
23
24 $regular = $variation->get_regular_price();
25 $sale = $variation->get_sale_price();
26
27 if (!$regular || !$sale) continue;
28
29 $discount = $this->discountService->calculateDiscountPercent($regular, $sale);
30 $this->discountService->apply($discount, null, [$basalam_id], null);
31 }
32 }
33
34 public function remove($product): void
35 {
36 $basalam_ids = [];
37 foreach ($product->get_children() as $variation_id) {
38 $basalam_id = get_post_meta($variation_id, 'sync_basalam_variation_id', true);
39 if ($basalam_id) $basalam_ids[] = $basalam_id;
40 }
41 if (!empty($basalam_ids)) $this->discountService->remove(null, $basalam_ids);
42 }
43 }
44