示例#1
0
 protected function getItems($order, $targetCurrencyCode)
 {
     $items = $order->getAllItems();
     foreach ($items as $item) {
         $product_id = $item->getProductId();
         foreach ($order->getAllItems() as $order_item) {
             $order_product_id = $order_item->getProductId();
             if ($order_product_id == $product_id) {
                 $quantity = round($order_item->getQtyOrdered(), 2);
             }
         }
         if ($item->getParentItem()) {
             continue;
         }
         $taxClass = $item->getTaxPercent() == 0 ? 'none' : $item->getTaxPercent();
         $rate = $item->getTaxPercent() / 100;
         $table = new MspAlternateTaxTable();
         $table->name = $item->getTaxPercent();
         $rule = new MspAlternateTaxRule($rate);
         $table->AddAlternateTaxRules($rule);
         $this->api->cart->AddAlternateTaxTables($table);
         $weight = (double) $item->getWeight();
         $product_id = $item->getProductId();
         // name and options
         $itemName = $item->getName();
         $options = $this->getProductOptions($item);
         if (!empty($options)) {
             $optionString = '';
             foreach ($options as $option) {
                 $optionString = $option['label'] . ": " . $option['print_value'] . ",";
             }
             $optionString = substr($optionString, 0, -1);
             $itemName .= ' (';
             $itemName .= $optionString;
             $itemName .= ')';
         }
         $proddata = Mage::getModel('catalog/product')->load($product_id);
         $currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
         //$quantity = round($item->getQtyOrdered(), 2);
         $ndata = $item->getData();
         if ($ndata['price'] != 0) {
             //Test-> Magento rounds at 2 decimals so the recalculation goes wrong with large quantities.
             $price_with_tax = $ndata['price_incl_tax'];
             $tax_rate = $rate;
             $divided_value = 1 + $tax_rate;
             $price_without_tax = $price_with_tax / $divided_value;
             $price = round($price_without_tax, 4);
             $price = number_format($this->_convertCurrency($price, $currentCurrencyCode, $targetCurrencyCode), 4, '.', '');
             $tierprices = $proddata->getTierPrice();
             if (count($tierprices) > 0) {
                 $product_tier_prices = (object) $tierprices;
                 $product_price = array();
                 foreach ($product_tier_prices as $key => $value) {
                     $value = (object) $value;
                     $product_price[] = $value->price;
                     if ($item->getQtyOrdered() >= $value->price_qty) {
                         $price_with_tax = $value->price;
                     }
                     $tax_rate = $rate;
                     $divided_value = 1 + $tax_rate;
                     $price_without_tax = $price_with_tax / $divided_value;
                     $price = round($price_without_tax, 4);
                     $price = number_format($this->_convertCurrency($price, $currentCurrencyCode, $targetCurrencyCode), 4, '.', '');
                 }
             }
             // create item
             $c_item = new MspItem($itemName, $item->getDescription(), $quantity, $price, 'KG', $item->getWeight());
             $c_item->SetMerchantItemId($item->getSku());
             $c_item->SetTaxTableSelector($taxClass);
             $this->api->cart->AddItem($c_item);
         }
     }
 }
 function setDefaultTaxZones($globalRate = true, $shippingTaxed = true)
 {
     $shippingTaxed = $shippingTaxed ? 'true' : 'false';
     if ($globalRate) {
         $rule = new MspDefaultTaxRule('0.21', $shippingTaxed);
         $this->cart->AddDefaultTaxRules($rule);
     }
     $table = new MspAlternateTaxTable('BTW21', 'true');
     $rule = new MspAlternateTaxRule('0.21');
     $table->AddAlternateTaxRules($rule);
     $this->cart->AddAlternateTaxTables($table);
     $table = new MspAlternateTaxTable('BTW6', 'true');
     $rule = new MspAlternateTaxRule('0.06');
     $table->AddAlternateTaxRules($rule);
     $this->cart->AddAlternateTaxTables($table);
     $table = new MspAlternateTaxTable('BTW0', 'true');
     $rule = new MspAlternateTaxRule('0.00');
     $table->AddAlternateTaxRules($rule);
     $this->cart->AddAlternateTaxTables($table);
 }
示例#3
0
 protected function _getTaxTable($rules, $type)
 {
     if (is_array($rules)) {
         foreach ($rules as $group => $taxRates) {
             if ($type != 'default') {
                 $table = new MspAlternateTaxTable($group, 'true');
                 $shippingTaxed = 'false';
             } else {
                 $shippingTaxed = 'true';
             }
             if (is_array($taxRates)) {
                 foreach ($taxRates as $rate) {
                     if ($type != 'default') {
                         $rule = new MspAlternateTaxRule($rate['value']);
                         $rule->AddPostalArea($rate['country']);
                         $table->AddAlternateTaxRules($rule);
                     } else {
                         $rule = new MspDefaultTaxRule($rate['value'], $shippingTaxed);
                         $rule->AddPostalArea($rate['country']);
                         $this->api->cart->AddDefaultTaxRules($rule);
                     }
                 }
             } else {
                 $taxRate = $taxRates / 100;
                 if ($type != 'default') {
                     $rule = new MspAlternateTaxRule($taxRate);
                     $rule->SetWorldArea();
                     $table->AddAlternateTaxRules($rule);
                 } else {
                     $rule = new MspDefaultTaxRule($taxRate, $shippingTaxed);
                     $rule->SetWorldArea();
                     $this->api->cart->AddDefaultTaxRules($rule);
                 }
             }
             if ($type != 'default') {
                 $this->api->cart->AddAlternateTaxTables($table);
             }
         }
     } else {
         if (is_numeric($rules)) {
             $taxRate = $rules / 100;
             if ($type != 'default') {
                 $table = new MspAlternateTaxTable();
                 $rule = new MspAlternateTaxRule($taxRate);
                 $rule->SetWorldArea();
                 $table->AddAlternateTaxRules($rule);
                 $this->api->cart->AddAlternateTaxTables($table);
                 print_r($table);
                 //Validate this one!
             } else {
                 $rule = new MspDefaultTaxRule($taxRate, 'true');
                 $rule->SetWorldArea();
                 $this->api->cart->AddDefaultTaxRules($rule);
             }
         }
     }
 }