/**
  * @param \Heystack\Core\EventDispatcher $eventService
  * @param \Heystack\Ecommerce\Purchasable\Interfaces\PurchasableHolderInterface $purchasableHolder
  * @param \Heystack\Ecommerce\Currency\Interfaces\CurrencyServiceInterface $currencyService
  * @param \Heystack\Deals\Interfaces\AdaptableConfigurationInterface $configuration
  * @throws \Exception when configured incorrectly
  */
 public function __construct(EventDispatcher $eventService, PurchasableHolderInterface $purchasableHolder, CurrencyServiceInterface $currencyService, AdaptableConfigurationInterface $configuration)
 {
     $this->eventService = $eventService;
     $this->purchasableHolder = $purchasableHolder;
     $this->currencyService = $currencyService;
     $discountConfigured = false;
     if ($configuration->hasConfig(self::CART_DISCOUNT_AMOUNTS)) {
         if ($discountConfigured) {
             throw new \Exception('Cart Discount Result requires that only one discount is configured. Please remove one of the following: ' . $discountConfigured . ',  ' . self::CART_DISCOUNT_AMOUNTS);
         }
         $discountAmounts = $configuration->getConfig(self::CART_DISCOUNT_AMOUNTS);
         if (is_array($discountAmounts) && count($discountAmounts)) {
             $this->discountAmounts = $discountAmounts;
             $discountConfigured = self::CART_DISCOUNT_AMOUNTS;
         } else {
             throw new \Exception('Cart Discount Result requires that the discount amounts are configured using an array of amounts with their indexes being the currency code.');
         }
     }
     if ($configuration->hasConfig(self::CART_DISCOUNT_PERCENTAGE)) {
         if ($discountConfigured) {
             throw new \Exception('Cart Discount Result requires that only one discount is configured. Please remove one of the following: ' . $discountConfigured . ',  ' . self::CART_DISCOUNT_PERCENTAGE);
         }
         $this->discountPercentage = (double) $configuration->getConfig(self::CART_DISCOUNT_PERCENTAGE);
     }
 }
 /**
  * @param LocaleServiceInterface $localeService
  * @param AdaptableConfigurationInterface $configuration
  * @throws \Exception when the configuration is not setup properly
  */
 public function __construct(LocaleServiceInterface $localeService, AdaptableConfigurationInterface $configuration)
 {
     if ($configuration->hasConfig(self::COUNTRY_CODES)) {
         $this->countryCodes = $configuration->getConfig(self::COUNTRY_CODES);
     } else {
         throw new \Exception('Zone Condition requires an array of allowed country codes to be configured');
     }
     $this->localeService = $localeService;
 }
 /**
  * @param \Heystack\Deals\Interfaces\CouponHolderInterface $couponHolder
  * @param \Heystack\Deals\Interfaces\AdaptableConfigurationInterface $configuration
  * @throws \Exception
  */
 public function __construct(CouponHolderInterface $couponHolder, AdaptableConfigurationInterface $configuration)
 {
     $this->couponHolder = $couponHolder;
     if ($configuration->hasConfig(self::COUPON_IDENTIFIERS) && is_array($configuration->getConfig(self::COUPON_IDENTIFIERS))) {
         $this->couponIdentifiers = $configuration->getConfig(self::COUPON_IDENTIFIERS);
     } else {
         throw new \Exception('Has Coupon Condition requires an array of coupon identifiers');
     }
 }
 /**
  * @param \Heystack\Deals\Interfaces\AdaptableConfigurationInterface $configuration
  * @throws \Exception if the configuration does not have a 'start' value
  */
 public function __construct(AdaptableConfigurationInterface $configuration)
 {
     if ($configuration->hasConfig(self::START_KEY)) {
         $this->startDate = strtotime($configuration->getConfig(self::START_KEY));
     } else {
         throw new \Exception('Start Date Condition requires a start date');
     }
     // Set up a default currentTime, but allow the value to be overridden through a setter.
     $this->currentTime = time();
 }
 /**
  * The amount condition determines whether the total in the product holder is greater than or equal to the configured threshold amount.
  * It takes into consideration the different currencies.
  *
  * @param \Heystack\Ecommerce\Purchasable\Interfaces\PurchasableHolderInterface $purchasableHolder
  * @param \Heystack\Ecommerce\Currency\Interfaces\CurrencyServiceInterface $currencyService
  * @param \Heystack\Deals\Interfaces\AdaptableConfigurationInterface $configuration
  * @throws \Exception if the configuration does not have a configuration identifier
  */
 public function __construct(PurchasableHolderInterface $purchasableHolder, CurrencyServiceInterface $currencyService, AdaptableConfigurationInterface $configuration)
 {
     if ($configuration->hasConfig(self::AMOUNTS_KEY)) {
         $this->amounts = $configuration->getConfig(self::AMOUNTS_KEY);
     } else {
         throw new \Exception('Minimum Cart Total Condition needs to be configured with all the amounts in the different currencies');
     }
     $this->purchasableHolder = $purchasableHolder;
     $this->currencyService = $currencyService;
 }
 /**
  * @param \Heystack\Core\EventDispatcher $eventService
  * @param \Heystack\Ecommerce\Purchasable\Interfaces\PurchasableHolderInterface $purchasableHolder
  * @param \Heystack\Deals\Interfaces\AdaptableConfigurationInterface $configuration
  * @throws \Exception
  */
 public function __construct(EventDispatcher $eventService, PurchasableHolderInterface $purchasableHolder, AdaptableConfigurationInterface $configuration)
 {
     $this->eventService = $eventService;
     $this->purchasableHolder = $purchasableHolder;
     if ($configuration->hasConfig(self::PURCHASABLE_IDENTIFIER_STRINGS)) {
         $purchasableIdentifierStrings = $configuration->getConfig(self::PURCHASABLE_IDENTIFIER_STRINGS);
         if (is_array($purchasableIdentifierStrings) && count($purchasableIdentifierStrings)) {
             foreach ($purchasableIdentifierStrings as $purchasableIdentifierString) {
                 $this->purchasableIdentifiers[] = new Identifier($purchasableIdentifierString);
             }
         } else {
             throw new \Exception('Cheapest Purchasable Discount Result requires that the purchasable identifier strings are itemized in an array');
         }
     }
 }
 /**
  * @param \Heystack\Core\EventDispatcher $eventService
  * @param \Heystack\Ecommerce\Purchasable\Interfaces\PurchasableHolderInterface $purchasableHolder
  * @param \Heystack\Ecommerce\Currency\Interfaces\CurrencyServiceInterface $currencyService
  * @param \Heystack\Deals\Interfaces\AdaptableConfigurationInterface $configuration
  * @throws \Exception if the configuration is incorrect
  */
 public function __construct(EventDispatcher $eventService, PurchasableHolderInterface $purchasableHolder, CurrencyServiceInterface $currencyService, AdaptableConfigurationInterface $configuration)
 {
     $this->eventService = $eventService;
     $this->purchasableHolder = $purchasableHolder;
     $this->currencyService = $currencyService;
     if ($configuration->hasConfig(self::PURCHASABLE_CLASS)) {
         $this->purchasableClass = $configuration->getConfig(self::PURCHASABLE_CLASS);
     } else {
         throw new \Exception('Free Gift Result requires a purchasable_class configuration value');
     }
     if ($configuration->hasConfig(self::PURCHASABLE_ID)) {
         $this->purchasableID = $configuration->getConfig(self::PURCHASABLE_ID);
     } else {
         throw new \Exception('Free Gift Result requires a purchasable_id configuration value');
     }
 }
 /**
  * @param \Heystack\Ecommerce\Purchasable\Interfaces\PurchasableHolderInterface $purchasableHolder
  * @param \Heystack\Deals\Interfaces\AdaptableConfigurationInterface $configuration
  * @throws \Exception if the configuration does not have a purchasable identifier
  */
 public function __construct(PurchasableHolderInterface $purchasableHolder, AdaptableConfigurationInterface $configuration)
 {
     if ($configuration->hasConfig(self::PURCHASABLE_IDENTIFIERS) && is_array($purchasableIdentifiers = $configuration->getConfig(self::PURCHASABLE_IDENTIFIERS))) {
         foreach ($purchasableIdentifiers as $purchasableIdentifier) {
             $this->purchasableIdentifiers[] = new Identifier($purchasableIdentifier);
         }
     } else {
         throw new \Exception('Quantity Of Purchasables In Cart Condition requires an array of purchasable identifiers');
     }
     if ($configuration->hasConfig(self::MINIMUM_QUANTITY_KEY)) {
         $this->minimumQuantity = $configuration->getConfig(self::MINIMUM_QUANTITY_KEY);
     } else {
         throw new \Exception('Quantity Of Purchasables In Cart Condition requires a minimum quantity to be configured');
     }
     $this->configuration = $configuration;
     $this->purchasableHolder = $purchasableHolder;
 }
 /**
  * @param \Heystack\Core\EventDispatcher $eventService
  * @param \Heystack\Shipping\Interfaces\ShippingHandlerInterface $shippingHandler
  * @param \Heystack\Ecommerce\Currency\Interfaces\CurrencyServiceInterface $currencyService
  * @param \Heystack\Deals\Interfaces\AdaptableConfigurationInterface $configuration
  * @throws \Exception
  */
 public function __construct(EventDispatcher $eventService, ShippingHandlerInterface $shippingHandler, CurrencyServiceInterface $currencyService, AdaptableConfigurationInterface $configuration)
 {
     $this->eventService = $eventService;
     $this->shippingHandler = $shippingHandler;
     $this->currencyService = $currencyService;
     $discountConfigured = false;
     if ($configuration->hasConfig(self::FREE_SHIPPING)) {
         $this->isFree = true;
         $discountConfigured = self::FREE_SHIPPING;
     }
     if ($configuration->hasConfig(self::SHIPPING_DISCOUNT_AMOUNTS)) {
         if ($discountConfigured) {
             throw new \Exception('Shipping Result requires that only one discount is configured. Please remove one of the following: ' . $discountConfigured . ',  ' . self::SHIPPING_DISCOUNT_AMOUNTS);
         }
         $discountAmounts = $configuration->getConfig(self::SHIPPING_DISCOUNT_AMOUNTS);
         if (is_array($discountAmounts) && count($discountAmounts)) {
             $this->discountAmounts = $discountAmounts;
             $discountConfigured = self::SHIPPING_DISCOUNT_AMOUNTS;
         } else {
             throw new \Exception('Shipping Result requires that the discount amounts are configured using an array of amounts with their indexes being the currency code.');
         }
     }
     if ($configuration->hasConfig(self::SHIPPING_DISCOUNT_PERCENTAGE)) {
         if ($discountConfigured) {
             throw new \Exception('Shipping Result requires that only one discount is configured. Please remove one of the following: ' . $discountConfigured . ',  ' . self::SHIPPING_DISCOUNT_AMOUNTS);
         }
         $this->discountPercentage = $configuration->getConfig(self::SHIPPING_DISCOUNT_PERCENTAGE);
         $discountConfigured = self::SHIPPING_DISCOUNT_PERCENTAGE;
     }
 }
 /**
  * @param \Heystack\Core\EventDispatcher $eventService
  * @param \Heystack\Ecommerce\Purchasable\Interfaces\PurchasableHolderInterface $purchasableHolder
  * @param \Heystack\Ecommerce\Currency\Interfaces\CurrencyServiceInterface $currencyService
  * @param \Heystack\Deals\Interfaces\AdaptableConfigurationInterface $configuration
  * @throws \Exception when configured incorrectly
  */
 public function __construct(EventDispatcher $eventService, PurchasableHolderInterface $purchasableHolder, CurrencyServiceInterface $currencyService, AdaptableConfigurationInterface $configuration)
 {
     $this->eventService = $eventService;
     $this->purchasableHolder = $purchasableHolder;
     $this->currencyService = $currencyService;
     $discountConfigured = false;
     if ($configuration->hasConfig(self::PURCHASABLE_DISCOUNT_AMOUNTS)) {
         if ($discountConfigured) {
             throw new \Exception('Purchasable Discount Result requires that only one discount is configured. Please remove one of the following: ' . $discountConfigured . ',  ' . self::PURCHASABLE_DISCOUNT_AMOUNTS);
         }
         $discountAmounts = $configuration->getConfig(self::PURCHASABLE_DISCOUNT_AMOUNTS);
         if (is_array($discountAmounts) && count($discountAmounts)) {
             $this->discountAmounts = $discountAmounts;
             $discountConfigured = self::PURCHASABLE_DISCOUNT_AMOUNTS;
         } else {
             throw new \Exception('Purchasable Discount Result requires that the discount amounts are configured using an array of amounts with their indexes being the currency code.');
         }
     }
     if ($configuration->hasConfig(self::PURCHASABLE_DISCOUNT_PERCENTAGE)) {
         if ($discountConfigured) {
             throw new \Exception('Purchasable Discount Result requires that only one discount is configured. Please remove one of the following: ' . $discountConfigured . ',  ' . self::PURCHASABLE_DISCOUNT_PERCENTAGE);
         }
         $this->discountPercentage = $configuration->getConfig(self::PURCHASABLE_DISCOUNT_PERCENTAGE);
     }
     if ($configuration->hasConfig(self::PURCHASABLE_IDENTIFIER_STRINGS)) {
         $purchasableIdentifierStrings = $configuration->getConfig(self::PURCHASABLE_IDENTIFIER_STRINGS);
         if (is_array($purchasableIdentifierStrings) && count($purchasableIdentifierStrings)) {
             foreach ($purchasableIdentifierStrings as $purchasableIdentifierString) {
                 $this->purchasableIdentifiers[] = new Identifier($purchasableIdentifierString);
             }
         } else {
             throw new \Exception('Purchasable Discount Result requires that the purchasable identifier strings are itemized in an array');
         }
     } else {
         throw new \Exception('Purchasable Discount Result requires a purchasable identifier string configuration');
     }
 }