예제 #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);
         }
     }
 }
예제 #2
0
 protected function getItems()
 {
     foreach ($this->_quote->getAllItems() as $item) {
         if ($item->getParentItem()) {
             continue;
         }
         $taxClass = $item->getTaxClassId() == 0 ? 'none' : $item->getTaxClassId();
         $weight = (double) $item->getWeight();
         // 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 .= ')';
         }
         $price = round($item->getBaseCalculationPrice(), 2);
         // Magento uses the rounded number, so we do too
         //code below was disabled, this is now activated again to avoid rounding problems
         if (Mage::helper("Tax")->priceIncludesTax()) {
             $priceIncl = $item->getBasePriceInclTax();
             $taxRate = $item->getTaxPercent();
             $price = $priceIncl / (1 + $taxRate / 100);
         }
         //$price	= number_format($item->getPrice(), 4, '.', '');
         $this->total_amount += $item->getBasePriceInclTax() * $item->getQty();
         // create item
         $c_item = new MspItem($itemName, $item->getDescription(), $item->getQty(), $price, 'KG', $item->getWeight());
         $c_item->SetMerchantItemId($item->getSku());
         $c_item->SetTaxTableSelector($taxClass);
         $this->api->cart->AddItem($c_item);
     }
 }