Пример #1
0
 /**
  * Returns tax rates for request and when US only uses five digit zip code lookups
  *
  * @param Varien_Object $request
  * @return array
  */
 protected function _getRates($request)
 {
     // Grab each current value
     $countryId = $request->getCountryId();
     $currentPostcode = $request->getPostcode();
     if ($countryId == 'US') {
         // Trim whitespace
         $newPostcode = preg_replace('/\\s+/', '', $request->getPostcode());
         // Snatch only the first five characters
         $newPostcode = substr($newPostcode, 0, 5);
         // Replace the request's zip code with one that now has 5 digits
         $request->setPostcode($newPostcode);
         // Find rates by the new 5-digit zip
         $rates = parent::_getRates($request);
         // Reset the request's postcode to what it was
         $request->setPostcode($currentPostcode);
     } else {
         // Non-US should just work normally
         $rates = parent::_getRates($request);
     }
     return $rates;
 }
Пример #2
0
    public function run()
    {
        $order = Mage::getModel('sales/order')->load(182395);
        

        $shipping = $order->getShippingAddress();
        if (empty($shipping)) {
            $shipping = $order->getBillingAddress();
        } 

        foreach ($order->getAllItems() as $item) {
             echo "Item # {$item->getId()}:\n";
             
        // tax calculator
        $request = Mage::getSingleton("tax/calculation");
        $customer = $this->getCustomerByOrder($order);
        $request->setCustomer($customer);
        
        $request = $request->getRateRequest($shipping, $order->getBillingAddress());
//print_r($request->getData());       
 $calc = new Mage_Tax_Model_Resource_Calculation();
//print_r($item->getData());
$product = Mage::getModel('catalog/product')->load($item->getProductId());
//echo $product->getTaxClassId();
$request->setProductClassId($product->getTaxClassId());        
$taxData = $calc->getRateInfo($request);
        $taxData = $taxData['process'][0]['rates'];
        
        $taxes = array();
        foreach ($taxData as $t) {//print_r($t);
            $taxes[] = $this->processTax($t);
        }

// Unique id
/*$oldtaxes = $taxes;
$taxes = array();
$ids = array();
foreach($oldtaxes AS $tx) {
  if(! @$ids[$tx['id']]) {
    $ids[$tx['id']] = TRUE;
    $taxes[] = $tx;
  }
}*/

print_r($taxes);
$taxdata = $taxes;             
$TaxLines = array();
        if (empty($taxdata)) {
            $TaxLines[] = new Gorilla_Greatplains_Model_Source_Data_OrderLineTaxes();
        } else {
            $itemTax = $item->getTaxAmount();
            $baseprice = $item->getRowTotal();
            $taxableprice = $this->getTaxablePrice($baseprice, $item->getDiscountAmount());

            $totalTax = 0;
            foreach ($taxdata as $line) {
                $t = new Gorilla_Greatplains_Model_Source_Data_OrderLineTaxes($line, $taxableprice,$itemTax);
                $TaxLines[] = $t;
                $totalTax += $t->TaxAmount;
            }

            //$itemtax = round($item, 2);

            if ($totalTax < $itemTax) {
                $difference = $itemTax - $totalTax;
                $TaxLines[0]->TaxAmount += $difference;
            }
            if ($totalTax > $itemTax) {
                $difference = $totalTax - $itemTax;
                $TaxLines[0]->TaxAmount -= $difference;
            }

        }

            print_r($TaxLines);

        }
    }