コード例 #1
0
 public function process($productID)
 {
     $product = $this->get('product.loader')->getByID($productID);
     $form = $this->_getForm($product);
     if ($form->isValid() && ($data = $form->getFilteredData())) {
         $basket = $this->get('basket');
         $unit = $product->getUnit($data['unit_id']);
         $fail = false;
         for ($i = 0; $i < $data['quantity']; ++$i) {
             $item = new Order\Entity\Item\Item();
             $item->order = $basket->getOrder();
             $item->stockLocation = $this->get('stock.locations')->get('web');
             $item->populate($unit);
             $item = $this->get('event.dispatcher')->dispatch(Events::PRODUCT_SELECTOR_PROCESS, new Event\ProductSelectorProcessEvent($form, $product, $item))->getItem();
             if (!$basket->addItem($item)) {
                 $this->addFlash('error', 'An item could not be added to your basket');
                 $fail = true;
                 break;
             }
         }
         if (!$fail) {
             $this->addFlash('success', 'Item added to basket');
         }
     }
     return $this->redirectToReferer();
 }
コード例 #2
0
 public function testGetTax()
 {
     $item = new Item();
     $item->populate($this->_unit);
 }
コード例 #3
0
 protected function _calculateTaxForItem(Item $item)
 {
     // populate for taxStrategy
     $item->populate($item->getUnit());
     if (false === $item->order->taxable) {
         // Resetting the gross is important because if the tax strategy is
         // exclusive this will include the tax amount
         $item->gross = $item->net;
         $item->taxRate = 0;
         $item->tax = 0;
         return;
     }
     // Set the tax rate to whatever the product's tax rate is
     $item->taxRate = $item->productTaxRate;
     // Get the adjusted gross based on tax rate differences.
     // Takes off included tax and add actual tax.
     if ('exclusive' === $item->taxStrategy) {
         // actual
         $adjustedGross = $item->getDiscountedPrice();
     } else {
         // actual - included tax
         $includedTax = $this->_calculateInclusiveTax($item->getDiscountedPrice(), $item->getProduct()->getTaxStrategy()->getIncludedTaxRate());
         $adjustedGross = $item->getDiscountedPrice() - $includedTax;
     }
     // adjusted + tax
     $adjustedGross += $adjustedGross * ($item->taxRate / 100);
     // Gross is the product gross - discount
     $item->gross = $adjustedGross;
     $item->tax = $this->_calculateInclusiveTax($item->gross, $item->taxRate);
     $item->net = round($item->gross - $item->tax, 2);
     $item->gross = round($item->gross, 2);
     $item->discount = round($item->discount, 2);
 }
コード例 #4
0
 /**
  * Add a unit to the order.
  *
  * The unit is transformed into an Item entity and has the stock location
  * set to the defined default stock location and is then added to the order.
  *
  * @param  Unit $unit The unit to add
  *
  * @return Assembler  Returns $this for chainability
  */
 public function addUnit(Unit $unit)
 {
     $item = new Entity\Item\Item();
     $item->order = $this->_order;
     $item->populate($unit);
     $item->stockLocation = $this->_defaultStockLocation;
     return $this->addItem($item);
 }
コード例 #5
0
 /**
  * Set the exchange item from a ProductUnit.
  *
  * @param ProductUnit $unit
  * @param null | StockLocation $stockLocation
  * @throws \LogicException
  *
  * @return Assembler
  */
 public function setExchangeItem(ProductUnit $unit, StockLocation $stockLocation = null)
 {
     if (!$this->_return->item) {
         throw new \LogicException("You can not set the exchange item without having previously set the return item");
     }
     $this->_return->item->exchangeItem = $item = new OrderItem();
     $item->populate($unit);
     $item->listPrice = $unit->getPrice('retail', $this->_currencyID);
     $item->actualPrice = $item->listPrice;
     $item->rrp = $unit->getPrice('rrp', $this->_currencyID);
     $item->basePrice = $item->actualPrice;
     $taxRates = $this->_taxLoader->getProductTaxRates($unit->product, $this->_return->getPayableAddress('delivery') ?: $this->_defaultAddress);
     // Re-evaluate tax rates for address
     $taxes = [];
     $item->taxRate = 0;
     foreach ($taxRates as $rate) {
         $taxes[$rate->getType()] = $rate->getRate();
         $item->taxRate += $rate->getRate();
     }
     $item->setTaxRates($taxes);
     $this->_calculateTax($item);
     $item->stockLocation = $stockLocation;
     // Adjust the balance to reflect the exchange item
     $balance = $item->gross - $this->_return->item->gross;
     $this->_return->item->calculatedBalance = $balance;
     return $this;
 }
コード例 #6
0
 /**
  * Check if an item matches the criteria set by the product row
  *
  * @param Order\Entity\Item\Item $item
  * @param ProductRow $row
  *
  * @return bool
  */
 public function itemIsApplicable(Order\Entity\Item\Item $item, ProductRow $row)
 {
     if (in_array($item->id, $this->_alreadyInBundle)) {
         return false;
     }
     if ((int) $item->getProduct()->id !== $row->getProductID()) {
         return false;
     }
     if (count($row->getOptions()) <= 0) {
         return true;
     }
     $unit = $item->getUnit();
     foreach ($row->getOptions() as $name => $value) {
         if (!($unit->hasOption($name) && $unit->getOption($name) === $value)) {
             return false;
         }
     }
     return true;
 }