Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

pricing set updates

  • Loading branch information...
commit f2a743f04b007d4b86f305d1d5503185d9d318d6 1 parent 4828127
@theodorDiaconu theodorDiaconu authored iampersistent committed
View
61 lib/ImmersiveLabs/Pricing/Entity/PricingSet.php
@@ -78,6 +78,16 @@ public function get($name)
return $this->processed[$name];
}
+ public function set($name, $value)
+ {
+ $this->processed[$name] = $value;
+ }
+
+ public function has($name, $value)
+ {
+ return isset($this->processed[$name]);
+ }
+
public function process($context = null)
{
// create empty array with keys from $this->processed
@@ -95,4 +105,55 @@ public function addElement(PricingElementInterface $element)
{
$this->pricingElements->add($element);
}
+
+
+ public function setContext($context)
+ {
+ $this->context = $context;
+ }
+
+ public function getContext()
+ {
+ return $this->context;
+ }
+
+ public function setPricingElements($pricingElements)
+ {
+ $this->pricingElements = $pricingElements;
+ }
+
+ public function getPricingElements()
+ {
+ return $this->pricingElements;
+ }
+
+ public function setProcessed($processed)
+ {
+ $this->processed = $processed;
+ }
+
+ public function getProcessed()
+ {
+ return $this->processed;
+ }
+
+ public function setProcessingState($processingState)
+ {
+ $this->processingState = $processingState;
+ }
+
+ public function getProcessingState()
+ {
+ return $this->processingState;
+ }
+
+ public function setReturns($returns)
+ {
+ $this->returns = $returns;
+ }
+
+ public function getReturns()
+ {
+ return $this->returns;
+ }
}
View
52 lib/ImmersiveLabs/Pricing/Provider/OrderPricingProvider.php
@@ -1,53 +1,73 @@
<?php
namespace ImmersiveLabs\Pricing\Provider;
+
use Vespolina\Entity\Order\OrderInterface;
+use ImmersiveLabs\Pricing\Entity\PricingSet;
use ImmersiveLabs\Pricing\Entity\PricingContext;
use Vespolina\Entity\Pricing\PricingContextInterface;
use Vespolina\Entity\Order\ItemInterface;
+use Vespolina\Order\Pricing\OrderPricingProviderInterface;
+use Vespolina\Order\Handler\OrderHandlerInterface;
-class OrderPricingProvider
+class OrderPricingProvider implements OrderPricingProviderInterface
{
// method that updates the pricing for the given order
- public function updatePricing(OrderInterface $order, PricingContextInterface $pricingContext = null)
+ public function determineOrderPrices(OrderInterface $order, PricingContextInterface $pricingContext = null)
{
// not implemented
if ($pricingContext === null) {
$pricingContext = $this->createPricingContext();
}
+ foreach ($order->getItems() as $item) {
+ $this->determineOrderItemPrices($item, $pricingContext);
+ }
+
+ // summing it up
$itemsTotalNet = 0;
+
// updating prices for each item
foreach ($order->getItems() as $item) {
/** @var ItemInterface $item */
$pricing = $item->getPricing();
- $itemsTotalNet += $pricing['netValue'];
+ $itemsTotalNet += $pricing['totalNet'];
}
- $previousTotal = $pricingContext->get('totalNet');
- $pricingContext->set('totalNet', $previousTotal + $itemsTotalNet);
+ if (!$pricingSet = $order->getPricing()) {
+ $pricingSet = new PricingSet();
+ $order->setPricing($pricingSet);
+ }
// if pricing context has taxation enabled we calculate the taxes with the percentage set
// example taxRates : 0.10 for 10%, 0.25 for 25%
if ($pricingContext->get('taxRate')) {
- $pricingContext->set('totalTax', $pricingContext->get('totalNet') * $pricingContext->get('taxRate'));
+ $pricingSet->set('totalNet', $itemsTotalNet);
+ $totalTax = $itemsTotalNet * $pricingContext->get('taxRate');
+ $pricingSet->set('totalTax', $totalTax);
+ $pricingSet->set('totalGross', $itemsTotalNet + $totalTax);
}
- return $pricingContext;
+ $pricingSet->setProcessingState(PricingSet::PROCESSING_FINISHED);
}
- /**
- * @return \ImmersiveLabs\Pricing\Entity\PricingContext
- */
- public function createPricingContext()
+ function createPricingSet()
{
- $pricingContext = new PricingContext();
- $pricingContext->set('totalNet', 0);
- $pricingContext->set('totalTax', 0);
- $pricingContext->set('totalGross', 0);
+ $pricingSet = new PricingSet();
- return $pricingContext;
+ return $pricingSet;
}
+ function addOrderHandler(OrderHandlerInterface $handler)
+ {
+ }
+ function determineOrderItemPrices(ItemInterface $item, PricingContextInterface $pricingContext)
+ {
+ $pricing = array();
+ $productPricing = $item->getProduct()->getPricingSet();
+ $pricing['totalNet'] = $item->getQuantity() * $productPricing['netValue'];
+
+ $item->setPricing($pricing);
+ }
}

0 comments on commit f2a743f

Please sign in to comment.
Something went wrong with that request. Please try again.