Created
March 13, 2012 23:38
-
-
Save inspiran/2032697 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* (c) 2011-2012 Vespolina Project http://www.vespolina-project.org | |
* | |
* This source file is subject to the MIT license that is bundled | |
* with this source code in the file LICENSE. | |
*/ | |
namespace Vespolina\CartBundle\Pricing; | |
use Doctrine\Common\Collections\ArrayCollection; | |
use Vespolina\CartBundle\Model\CartableItemInterface; | |
use Vespolina\CartBundle\Model\CartItemInterface; | |
use Vespolina\CartBundle\Pricing\CartableItemPricingHandlerInterface; | |
/** | |
* @author Daniel Kucharski <[email protected]> | |
* @author Richard Shank <[email protected]> | |
*/ | |
class DefaultCartableItemPricingHandler implements CartableItemPricingHandlerInterface | |
{ | |
protected $metadata; | |
public function __construct() | |
{ | |
$this->loadMetadata(); | |
} | |
public function determineCartItemPrices(CartableItemInterface $cartableItem, CartItemInterface $cartItem, $pricingContext) | |
{ | |
$unitPrice = $cartableItem->getPricing($this->metadata['unitPrice']); | |
$upcharge = 0; | |
foreach($cartItem->getOptions() as $type => $value) { | |
if ($productOption = $cartItem->getCartableItem()->getOptionSet(array($type => $value))) { | |
$upcharge += $productOption->getUpcharge(); | |
} | |
} | |
$pricingContext['upcharge'] = $upcharge; | |
$pricingContext['total'] = ($cartItem->getQuantity() * $unitPrice) + $upcharge; | |
} | |
protected function loadMetadata() | |
{ | |
$this->metadata = new ArrayCollection(); | |
$this->metadata->set('unitPrice', 'unitPrice'); //For now we map it 1:1 | |
$this->metadata->set('totalPrice', 'totalPrice'); | |
} | |
public function getMetadata() | |
{ | |
return $this->metadata; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment