示例#1
0
 public function testGetAddress()
 {
     $quote = $this->getMock('Mage_Sales_Model_Quote', array('getShippingAddress', 'getBillingAddress'), array(), '', false);
     $quote->expects($this->once())->method('getShippingAddress')->will($this->returnValue('shipping'));
     $quote->expects($this->once())->method('getBillingAddress')->will($this->returnValue('billing'));
     $this->_model->setQuote($quote);
     $quote->setItemsQty(2);
     $quote->setVirtualItemsQty(1);
     $this->assertEquals('shipping', $this->_model->getAddress(), 'Wrong shipping address');
     $quote->setItemsQty(2);
     $quote->setVirtualItemsQty(2);
     $this->assertEquals('billing', $this->_model->getAddress(), 'Wrong billing address');
 }
示例#2
0
 /**
  * Estimates tax amount for one item. Does not trigger a call if the shipping
  * address has no postal code, or if the postal code is set to "-" (OneStepCheckout)
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @return int
  */
 public function getItemTax($item)
 {
     if ($item->getAddress()->getPostcode() && $item->getAddress()->getPostcode() != '-') {
         if ($this->isProductCalculated($item)) {
             $tax = 0;
             foreach ($item->getChildren() as $child) {
                 $child->setAddress($item->getAddress());
                 $tax += $this->getItemTax($child);
             }
             return (double) $tax;
         } else {
             $ratesData = $this->_getRates();
             $id = $item->getId();
             $tax = isset($ratesData['items'][$id]['amt']) ? $ratesData['items'][$id]['amt'] : 0;
             return (double) $tax;
         }
     }
     return 0;
 }
示例#3
0
 /**
  * Adds all items in the cart to the request
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @return int
  */
 protected function _addItemsInCart($item)
 {
     if ($item->getAddress() instanceof Mage_Sales_Model_Quote_Address) {
         $items = $item->getAddress()->getAllItems();
     } elseif ($item->getQuote() instanceof Mage_Sales_Model_Quote) {
         $items = $item->getQuote()->getAllItems();
     } else {
         $items = array();
     }
     if (count($items) > 0) {
         $this->_initProductCollection($items);
         $this->_initTaxClassCollection($item->getAddress());
         foreach ($items as $item) {
             /** @var Mage_Sales_Model_Quote_Item $item */
             $this->_newLine($item);
         }
         $this->_request->setLines($this->_lines);
     }
     return count($this->_lines);
 }