Exemplo n.º 1
0
 /**
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  * @param \Generated\Shared\Transfer\ItemTransfer $currentItemTransfer
  * @param \Generated\Shared\Transfer\ClauseTransfer $clauseTransfer
  *
  * @return bool
  */
 public function isSatisfiedBy(QuoteTransfer $quoteTransfer, ItemTransfer $currentItemTransfer, ClauseTransfer $clauseTransfer)
 {
     $currentTime = $this->convertToSeconds($this->getCurrentTime());
     $compareWithTime = $this->convertToSeconds($clauseTransfer->getValue());
     $clauseTransfer->setValue($compareWithTime);
     return $this->comparators->compare($clauseTransfer, $currentTime);
 }
Exemplo n.º 2
0
 /**
  * @return void
  */
 public function testCompareWhenClauseValueIsEqualToProvidedProvidedShouldReturnFalse()
 {
     $more = $this->createNotEqual();
     $clauseTransfer = new ClauseTransfer();
     $clauseTransfer->setValue('1');
     $isMatching = $more->compare($clauseTransfer, '1');
     $this->assertFalse($isMatching);
 }
Exemplo n.º 3
0
 /**
  * @return void
  */
 public function testCompareWhenValueNotLessThanClauseShouldReturnFalse()
 {
     $less = $this->createLess();
     $clauseTransfer = new ClauseTransfer();
     $clauseTransfer->setValue('1');
     $isMatching = $less->compare($clauseTransfer, '2');
     $this->assertFalse($isMatching);
 }
Exemplo n.º 4
0
 /**
  * @return void
  */
 public function testCompareWhenValueNotExistingInClauseShouldReturnFalse()
 {
     $contains = $this->createContains();
     $clauseTransfer = new ClauseTransfer();
     $clauseTransfer->setValue('zero');
     $isMatching = $contains->compare($clauseTransfer, ' oNe TwO ');
     $this->assertFalse($isMatching);
 }
Exemplo n.º 5
0
 /**
  * @return void
  */
 public function testCompareWhenClauseValueIsEqualShouldReturnTrue()
 {
     $moreEqual = $this->createMoreEqual();
     $clauseTransfer = new ClauseTransfer();
     $clauseTransfer->setValue('1');
     $isMatching = $moreEqual->compare($clauseTransfer, '1');
     $this->assertTrue($isMatching);
 }
Exemplo n.º 6
0
 /**
  * @return void
  */
 public function testCompareWhenValueNotMatchingClauseShouldReturnFalse()
 {
     $equal = $this->createEqual();
     $clauseTransfer = new ClauseTransfer();
     $clauseTransfer->setValue('2');
     $isMatching = $equal->compare($clauseTransfer, '1');
     $this->assertFalse($isMatching);
 }
Exemplo n.º 7
0
 /**
  * @return void
  */
 public function testConvertDecimalToCentWhenSingleValueUsedShouldUpdateAllItems()
 {
     $currencyConverterMock = $this->createMoneyValueConverter();
     $clauseTransfer = new ClauseTransfer();
     $clauseTransfer->setValue('10,50');
     $clauseTransfer->setOperator(IsIn::EXPRESSION);
     $currencyConverterMock->convertDecimalToCent($clauseTransfer);
     $this->assertEquals(1050, $clauseTransfer->getValue());
 }
Exemplo n.º 8
0
 /**
  * @param \Generated\Shared\Transfer\ClauseTransfer $clauseTransfer
  *
  * @throws \Spryker\Zed\Discount\Business\Exception\QueryStringException
  *
  * @return \Spryker\Zed\Discount\Business\QueryString\Specification\DecisionRuleSpecification\DecisionRuleSpecificationInterface
  */
 public function getSpecificationContext(ClauseTransfer $clauseTransfer)
 {
     foreach ($this->decisionRulePlugins as $decisionRulePlugin) {
         if (strcasecmp($decisionRulePlugin->getFieldName(), $clauseTransfer->getField()) === 0) {
             return new DecisionRuleContext($decisionRulePlugin, $clauseTransfer);
         }
     }
     throw new QueryStringException(sprintf('Could not find decision rule plugin for "%s" field. Have you registered it in "%s::getDecisionRulePlugins" plugins stack?', $clauseTransfer->getField(), DiscountDependencyProvider::class));
 }
Exemplo n.º 9
0
 /**
  * @return void
  */
 public function testCompareWhenValueIsNotInClauseShouldReturnFalse()
 {
     $isIn = $this->createIsIn();
     $clauseTransfer = new ClauseTransfer();
     $list = implode(ComparatorOperators::LIST_DELIMITER, [2, 3]);
     $clauseTransfer->setValue($list);
     $isMatching = $isIn->compare($clauseTransfer, '1');
     $this->assertFalse($isMatching);
 }
Exemplo n.º 10
0
 /**
  * @return void
  */
 public function testGetSpecificationContextShouldThrowExceptionWhenSpecificationNotFound()
 {
     $this->expectException(QueryStringException::class);
     $decisionRulePluginMock = $this->createCollectorPluginMock();
     $decisionRulePluginMock->expects($this->once())->method('getFieldName')->willReturn('does not exists');
     $clauseTransfer = new ClauseTransfer();
     $clauseTransfer->setField('sku');
     $decisionRuleProvider = $this->createCollectorProvider($decisionRulePluginMock);
     $decisionRuleProvider->getSpecificationContext($clauseTransfer);
 }
Exemplo n.º 11
0
 /**
  * @param \Generated\Shared\Transfer\ClauseTransfer $clauseTransfer
  * @param mixed $withValue
  *
  * @throws \Spryker\Zed\Discount\Business\Exception\ComparatorException
  *
  * @return bool
  */
 public function compare(ClauseTransfer $clauseTransfer, $withValue)
 {
     if ((string) $withValue === '') {
         return false;
     }
     if ($this->isMatchAllValue($clauseTransfer->getValue())) {
         return true;
     }
     foreach ($this->operators as $operator) {
         if (!$operator->accept($clauseTransfer)) {
             continue;
         }
         $this->assertTypeAccepted($clauseTransfer->getAcceptedTypes(), $operator);
         return $operator->compare($clauseTransfer, $withValue);
     }
     throw new ComparatorException(sprintf('Comparison operator "%s" not found.', $clauseTransfer->getOperator()));
 }
Exemplo n.º 12
0
 /**
  * @param \Generated\Shared\Transfer\ClauseTransfer $clauseTransfer
  *
  * @throws \Spryker\Zed\Discount\Business\Exception\QueryStringException
  *
  * @return void
  */
 protected function validateIfFieldIsRegistered(ClauseTransfer $clauseTransfer)
 {
     $clauseField = $clauseTransfer->getField();
     if ($clauseTransfer->getAttribute()) {
         $clauseField = $clauseField . '.' . $clauseTransfer->getAttribute();
     }
     foreach ($this->metaDataProvider->getAvailableFields() as $field) {
         if ($field === $clauseField) {
             return;
         }
     }
     throw new QueryStringException(sprintf('Could not found for field with name "%s".', $clauseTransfer->getField()));
 }
Exemplo n.º 13
0
 /**
  * @param \Generated\Shared\Transfer\ClauseTransfer $clauseTransfer
  *
  * @return bool
  */
 public function accept(ClauseTransfer $clauseTransfer)
 {
     return strcasecmp($clauseTransfer->getOperator(), $this->getExpression()) === 0;
 }
Exemplo n.º 14
0
 /**
  * @return void
  */
 public function testWhenNoneOfComparatorsAcceptsClauseShouldThrowException()
 {
     $this->expectException(ComparatorException::class);
     $equalComparatorMock = $this->createComparatorMock();
     $equalComparatorMock->expects($this->once())->method('accept')->willReturn(false);
     $comparatorOperators = $this->createComparatorOperators([$equalComparatorMock]);
     $clauseTransfer = new ClauseTransfer();
     $clauseTransfer->setOperator('not existing');
     $isValid = $comparatorOperators->compare($clauseTransfer, 'value');
     $this->assertFalse($isValid);
 }
Exemplo n.º 15
0
 /**
  * @param string $value
  *
  * @return \Generated\Shared\Transfer\ClauseTransfer
  */
 protected function createClauseTransfer($value)
 {
     $clauseTransfer = new ClauseTransfer();
     $clauseTransfer->setValue($value);
     return $clauseTransfer;
 }
Exemplo n.º 16
0
 /**
  * @param \Generated\Shared\Transfer\ClauseTransfer $clauseTransfer
  *
  * @return void
  */
 protected function convertSinglePrice(ClauseTransfer $clauseTransfer)
 {
     $amountInCents = $this->currencyManager->convertDecimalToCent($this->formatValue($clauseTransfer->getValue()));
     $clauseTransfer->setValue($amountInCents);
 }
Exemplo n.º 17
0
 /**
  * @return $this
  */
 protected function setAcceptedDataTypes()
 {
     return $this->clauseTransfer->setAcceptedTypes($this->rulePlugin->acceptedDataTypes());
 }
Exemplo n.º 18
0
 /**
  * @param string $token
  *
  * @return bool
  */
 protected function isComparator($token)
 {
     if (in_array($token, $this->getCompoundComparatorExpressions(), true)) {
         return true;
     }
     $clauseTransfer = new ClauseTransfer();
     $clauseTransfer->setOperator($token);
     return $this->comparatorOperators->isExistingComparator($clauseTransfer);
 }