Exemplo n.º 1
0
 /**
  * Apply promotional rules
  *
  * @return $this
  */
 public function applyPromotionalRules()
 {
     foreach ($this->promotionalRules->getAll() as $promotionalRule) {
         if ($promotionalRule instanceof PromotionalRuleApplyInterface) {
             if ($promotionalRule->needApply($this)) {
                 $promotionalRule->apply($this);
             }
         }
     }
     return $this;
 }
Exemplo n.º 2
0
 /**
  * SetUp
  */
 protected function setUp()
 {
     $promotionalRule = \Phake::mock(PromotionalRuleInterface::class);
     \Phake::when($promotionalRule)->needApply(\Phake::anyParameters())->thenReturn(false);
     \Phake::when($promotionalRule)->getName()->thenReturn('promotional1');
     $promotionalRule2 = \Phake::mock(PromotionalRuleInterface::class);
     \Phake::when($promotionalRule2)->needApply(\Phake::anyParameters())->thenReturn(true);
     \Phake::when($promotionalRule2)->apply()->thenReturn(true);
     \Phake::when($promotionalRule2)->getName()->thenReturn('promotional2');
     $promotionalRuleContainer = new PromotionalRuleContainer();
     $promotionalRuleContainer->add($promotionalRule);
     $promotionalRuleContainer->add($promotionalRule2);
     $this->cartContainer = new CartContainer($promotionalRuleContainer);
 }
Exemplo n.º 3
0
<?php

/**
 * This file is part of the babylontest project
 *
 * (c) BRAMILLE Sébastien <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Babylon;

use Babylon\Container\PromotionalRuleContainer;
use Babylon\Model\Item;
use Babylon\PromotionalRule\MoreThanPercentPromotionalRule;
use Babylon\PromotionalRule\ProductPricePromotionalRule;
// Items
$item001 = new Item();
$item001->setName('Lavender heart')->setCode('001')->setPrice(9.25);
$item002 = new Item();
$item002->setName('Personalised cufflinks')->setCode('002')->setPrice(45);
$item003 = new Item();
$item003->setName('Kids T-shirt')->setCode('003')->setPrice(19.95);
// PromotionalRules
$rule1 = new ProductPricePromotionalRule();
$rule1->setItem($item001)->setValue(2)->setAmount(8.5);
$rule2 = new MoreThanPercentPromotionalRule();
$rule2->setAmount(60)->setValue(10);
$promotionalRuleContainer = new PromotionalRuleContainer();
$promotionalRuleContainer->add($rule1);
$promotionalRuleContainer->add($rule2);