PluginProbe
AliNext – WooCommerce Dropshipping Plugin for AliExpress / trunk
AliNext – WooCommerce Dropshipping Plugin for AliExpress vtrunk
ali2woo-lite / includes / classes / service / PriceFormulaSetService.php

PriceFormulaSetService.php in AliNext – WooCommerce Dropshipping Plugin for AliExpress trunk, at includes/classes/service/PriceFormulaSetService.php

84 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Description of PriceFormulaSetService
5 *
6 * @author Ali2Woo Team
7 */
8
9 namespace AliNext_Lite;;
10
11 use Exception;
12
13 class PriceFormulaSetService
14 {
15 private PriceFormulaRepository $PriceFormulaRepository;
16 private PriceFormulaSettingsRepository $PriceFormulaSettingsRepository;
17 private PriceFormulaSetFactory $PriceFormulaSetFactory;
18 private BackgroundProcessFactory $BackgroundProcessFactory;
19
20 public function __construct(
21 PriceFormulaRepository $PriceFormulaRepository,
22 PriceFormulaSettingsRepository $PriceFormulaSettingsRepository,
23 PriceFormulaSetFactory $PriceFormulaSetFactory,
24 BackgroundProcessFactory $BackgroundProcessFactory
25 ) {
26 $this->PriceFormulaRepository = $PriceFormulaRepository;
27 $this->PriceFormulaSettingsRepository = $PriceFormulaSettingsRepository;
28 $this->PriceFormulaSetFactory = $PriceFormulaSetFactory;
29 $this->BackgroundProcessFactory = $BackgroundProcessFactory;
30 }
31
32 public function buildFromSettings(string $setName): PriceFormulaSet
33 {
34 $PriceFormulaDefault = $this->PriceFormulaRepository->getDefaultFormula();
35 $ExtendedFormulas = $this->PriceFormulaRepository->getExtendedFormulas();
36
37 return $this->PriceFormulaSetFactory->createFormulaSet(
38 $setName,
39 $PriceFormulaDefault,
40 $ExtendedFormulas,
41 $this->PriceFormulaSettingsRepository->getPriceCents(),
42 $this->PriceFormulaSettingsRepository->getPriceComparedCents(),
43 $this->PriceFormulaSettingsRepository->getUseExtendedPriceMarkup(),
44 $this->PriceFormulaSettingsRepository->getUseComparedPriceMarkup(),
45 $this->PriceFormulaSettingsRepository->getAddShippingToPrice(),
46 $this->PriceFormulaSettingsRepository->getApplyPriceRulesAfterShippingCost(),
47 $this->PriceFormulaSettingsRepository->getPricingRulesType()
48 );
49 }
50
51 /**
52 * @throws ServiceException
53 * @throws Exception
54 */
55 public function choose(PriceFormulaSet $PriceFormulaSet): void
56 {
57 $ApplyPricingRulesProcess = $this->BackgroundProcessFactory
58 ->createProcessByCode(ApplyPricingRulesProcess::ACTION_CODE);
59
60 if ($ApplyPricingRulesProcess->is_queued()) {
61 $message = _x("Please wait until the current 'Apply Pricing Rules' process is complete.",
62 'error text', 'ali2woo');
63 throw new ServiceException($message);
64 }
65
66 $this->PriceFormulaRepository->setDefaultFormula(
67 $PriceFormulaSet->getDefaultFormula()
68 );
69
70 foreach ($PriceFormulaSet->getExtendedFormulas() as $PriceFormula) {
71 $this->PriceFormulaRepository->saveExtendedFormula($PriceFormula);
72 }
73
74 $this->PriceFormulaSettingsRepository
75 ->setPriceCents($PriceFormulaSet->getCents())
76 ->setPriceComparedCents($PriceFormulaSet->getComparedCents())
77 ->setUseExtendedPriceMarkup($PriceFormulaSet->getUseExtendedPriceMarkup())
78 ->setUseComparedPriceMarkup($PriceFormulaSet->getUseComparedPriceMarkup())
79 ->setAddShippingToPrice($PriceFormulaSet->getAddShippingToPrice())
80 ->setApplyPriceRulesAfterShippingCost($PriceFormulaSet->getApplyPriceRulesAfterShippingCost())
81 ->setPricingRulesType($PriceFormulaSet->getPricingRulesType());
82 }
83 }
84