handleError(new Exception(sprintf("Item range adjustment type '%s' not supported", $type))); } if (($type === self::TYPE_BULK and ! in_array($groupBy, self::BULK_AVAILABLE_GROUP_BY)) or ($type === self::TYPE_TIER and ! in_array($groupBy, self::TIER_AVAILABLE_GROUP_BY))) { $context->handleError( new Exception( sprintf( "Item range adjustment qty based '%s' not supported", $groupBy ) ) ); } $this->type = $type; $this->measurement = $measurement; $this->groupBy = $groupBy; $this->replaceAsCartAdjustment = false; $this->replaceCartAdjustmentCode = null; $this->selectedProductIds = array(); $this->selectedCategoryIds = array(); } /** * @param RangeDiscount $range */ public function addRange($range) { if ($range instanceof RangeDiscount) { $this->ranges[] = $range; } } /** * @param array $ranges */ public function setRanges($ranges) { $this->ranges = array(); foreach ($ranges as $range) { $this->addRange($range); } } /** * @return array */ public function getRanges() { return $this->ranges; } /** * @return string */ public function getType() { return $this->type; } /** * @return BulkMeasurementEnum */ public function getMeasurement() { return $this->measurement; } /** * @return string */ public function getGroupBy() { return $this->groupBy; } /** * @param bool $replace */ public function setReplaceAsCartAdjustment($replace) { $this->replaceAsCartAdjustment = boolval($replace); } /** * @return bool */ public function isReplaceWithCartAdjustment() { return $this->replaceCartAdjustmentCode && $this->replaceAsCartAdjustment; } /** * @param string $code */ public function setReplaceCartAdjustmentCode($code) { $this->replaceCartAdjustmentCode = (string)$code; } /** * @return string */ public function getReplaceCartAdjustmentCode() { return $this->replaceCartAdjustmentCode; } /** * @return bool */ public function isValid() { return count($this->ranges) > 0; } /** * @param string $promotionalMessage */ public function setPromotionalMessage($promotionalMessage) { $this->promotionalMessage = $promotionalMessage; } /** * @return string */ public function getPromotionalMessage() { return $this->promotionalMessage; } /** * @param array $selectedProductIds */ public function setSelectedProductIds($selectedProductIds) { $this->selectedProductIds = $selectedProductIds; } /** * @return array */ public function getSelectedProductIds() { return $this->selectedProductIds; } /** * @param array $selectedCategoryIds */ public function setSelectedCategoryIds($selectedCategoryIds) { $this->selectedCategoryIds = $selectedCategoryIds; } /** * @return array */ public function getSelectedCategoryIds() { return $this->selectedCategoryIds; } }