protected function createOrUpdateBusinessAgreements(array &$agreements, ItemInterface $item, $context = null) { $pricingSet = $item->getPricing(); $interval = $pricingSet->get('interval'); $cycles = $pricingSet->get('cycles'); if ($item->getAttribute('start_billing')) { $startsOn = $item->getAttribute('start_billing'); } elseif ($context['dueDate']) { $startsOn = $pricingSet->get('startsOn'); $date = explode(',', $startsOn->format('Y,m')); $startsOn->setDate($date[0], $date[1], $context['dueDate']); } else { $startsOn = new \DateTime($pricingSet->get('startsOn')); } $startTimestamp = $startsOn->getTimestamp(); //Find a suitable billing agreement $activeAgreement = null; foreach ($agreements as $agreement) { if ($agreement->getBillingInterval() == $interval && $agreement->getBillingCycles() == $cycles && $agreement->getInitialBillingDate()->getTimestamp() == $startTimestamp) { $activeAgreement = $agreement; } } if (null == $activeAgreement) { $activeAgreement = $this->billingManager->createBillingAgreement(); $this->initBillingAgreement($activeAgreement, $item->getParent(), $item); $activeAgreement->setInitialBillingDate($startsOn)->setBillingCycles($pricingSet->get('cycles'))->setBillingInterval($pricingSet->get('interval')); $agreements[] = $activeAgreement; } //$activeAgreement->addOrderItem($item); //$activePricingSet = $activeAgreement->getPricing(); //$activeAgreement->setPricing($pricingSet->plus($activePricingSet)); return $activeAgreement; }
protected function getOrderHandler(ItemInterface $cartItem) { $type = $cartItem->getProduct()->getType(); if (!isset($this->handlers[$type])) { //Fall back to the default handler return $this->handlers['default']; } return $this->handlers[$type]; }
protected function determineOrderItemTaxes(ItemInterface $orderItem, array $pricesToBeTaxed, $pricingContext) { $rate = 0; $taxes = array(); $totalTax = 0; //We currently assume that all order items use the default tax zone and associated tax rate $taxZone = $pricingContext->get('taxZone'); if (null != $taxZone) { $rate = $taxZone->getDefaultRate(); } //Each price which should be taxed is aggregated into one value, for instance shipment tax + sales tax //This is especially true for flat rate taxes, but insufficient for mixed tax rates foreach ($pricesToBeTaxed as $name => $value) { $taxValue = $rate * $value / 100; $totalTax += $taxValue; } $orderItem->setPrice('totalTax', $totalTax); }
function determineOrderItemPrices(ItemInterface $item, PricingContextInterface $pricingContext) { $productPricing = $item->getProduct()->getPricing(); $itemPricing = $productPricing->process($pricingContext); $item->setPricing($itemPricing); }
/** * Update an Order item that has been persisted. The Order itemwill be immediately flushed in the database * * @param \Vespolina\Entity\Order\OrderInterface $cart */ public function updateOrderItem(ItemInterface $orderItem) { $this->molino->save($orderItem->getParent()); }
protected function initOrderItem(ItemInterface $item) { if ($product = $item->getProduct()) { $item->setName($product->getName()); $item->setPrices($product->getPrices()); } }