magento如何获取发票功能中的订单小计?

时间:2018-04-12 10:04:33

标签: magento-1.9 observers subtotal totals

我想检查小计是否小于100,然后税5%否则12% 任何人都可以帮助我。我有观察员支持我在这个功能中获得发票功能我希望得到小计。 提前致谢

公共函数gstinvoice($ observer)     {         尝试         {

        if(!(Mage::getStoreConfig('gstcharge/options/enabled')))
        {
          return 0;
        }

        $invoiceId = $observer->getEvent()->getInvoice();

        $order=$observer->getEvent()->getInvoice()->getOrder();

        $quoteId=$order->getQuoteId();
        $quote = Mage::getModel('sales/quote')->getCollection()
                ->addFieldToFilter('entity_id', $quoteId)
                 ->getFirstItem();

        //$exckudingTax=$quote->getExclPrice();
        //$quoteId=$order->getQuoteId();
        //$quote = Mage::getModel('sales/quote')->load($quoteId);
        //$exckudingTax=$quote->getExclPrice();

        $shippingAddress = $order->getShippingAddress();

          if($shippingAddress)
          {
              $CountryId=$shippingAddress->getCountryId();
              $CountryId=$shippingAddress->getCountryId();
              $CustomerRegionId=$shippingAddress->getRegionId();
              $SystemRegionId=Mage::getStoreConfig('gstcharge/options/state');

              if($CountryId!='IN')
              {
                    return 0;
              }

              $TotalGstPrice=0;

              foreach($invoiceId->getAllItems() as $item)
               {
                     $gstPercent=0;

                     $product=Mage::getModel('catalog/product')->load($item->getProductId());

                     $itemPriceAfterDiscount= ($item->getDiscountAmount() / $item->getPrice()) * 100 ;

                     $prdPrice=$item->getPrice()-$itemPriceAfterDiscount;

                     $gstPercent=$product->getGstSource();
                     $gstPercentMinPrice=$product->getGstSourceMinprice();
                     $gstPercentAfterMinprice=$product->getGstSourceAfterMinprice();

                     if($gstPercent<=0)
                     {
                         $cats = $product->getCategoryIds();
                           foreach ($cats as $category_id) 
                           {
                                $_cat = Mage::getModel('catalog/category')->load($category_id) ;

                                $gstPercent=$_cat->getGstCatSource();
                                $gstPercentMinPrice=$_cat->getGstCatSourceMinprice();
                                $gstPercentAfterMinprice=$_cat->getGstCatSourceAfterMinprice();

                                if($gstPercent!='')
                                {
                                    if($gstPercentMinPrice > 0 && $gstPercentMinPrice > $prdPrice )   
                                    {
                                        $gstPercent=$gstPercentAfterMinprice;
                                    }
                                    break;
                                }
                           }  
                     }
                     else
                     {
                        if($gstPercentMinPrice > 0 && $gstPercentMinPrice > $prdPrice )   
                        {
                            $gstPercent=$gstPercentAfterMinprice;
                        }
                     }


                    if($gstPercent<=0)
                    {
                          $gstPercent               =   Mage::getStoreConfig('gstcharge/options/tax_percent');
                          $gstPercentMinPrice       =   Mage::getStoreConfig('gstcharge/options/tax_minprice');
                          $gstPercentAfterMinprice  =   Mage::getStoreConfig('gstcharge/options/tax_percent_minprice');

                          if($gstPercentMinPrice > 0 && $gstPercentMinPrice > $prdPrice )   
                          {
                                $gstPercent=$gstPercentAfterMinprice;
                          }
                    }

                     $productPrice = $item->getPrice();
                     $qty          = $item->getQty();
                     $rowTotal     = $item->getRowTotal();
                     $DiscountAmount=$item->getDiscountAmount();

                    if($exckudingTax)
                    {

                        $GstPrice= ((($rowTotal-$DiscountAmount)*$gstPercent)/100);   
                    }
                    else
                    {
                    $quoteId=$order->getQuoteId();
                    $quote = Mage::getModel('sales/quote')->load($quoteId);
                    // $subtotal = round($totals["subtotal"]->getValue());
                    $subtotal=$quote->getSubtotal();
                        // echo $subtotal; 
                         if($subtotal<=1000){
                        // $gstPercent=5;
                        $totalPercent = 100 + $gstPercent;

                        $GstPrice= ((($rowTotal-$DiscountAmount)*$gstPercent)/100);
                        //$perPrice     = ($rowTotal-$DiscountAmount) / $totalPercent;
                        //$GstPrice     = $perPrice * $gstPercent;
                        }else{
                         $gstPercent=12;
                        $totalPercent = 100 + $gstPercent;
                        $GstPrice= ((($rowTotal-$DiscountAmount)*$gstPercent)/100);
                        //$perPrice     = ($rowTotal-$DiscountAmount) / $totalPercent;
                        //$GstPrice     = $perPrice * $gstPercent;
                        }
                    }

                    //$GstPrice= ((($rowTotal-$DiscountAmount)*$gstPercent)/100);
                   $TotalGstPrice+=$GstPrice;

                     //$GstPrice= ((($rowTotal-$DiscountAmount)*$gstPercent)/100);

                     if($CountryId=='IN' && $CustomerRegionId==$SystemRegionId)
                     {
                         $item->setCgstCharge($GstPrice/2);
                         $item->setCgstPercent($gstPercent/2);
                         $item->setSgstCharge($GstPrice/2);
                         $item->setSgstPercent($gstPercent/2);

                     }
                     else if ($CountryId=='IN' && $CustomerRegionId!=$SystemRegionId)
                     {
                           $item->setIgstCharge($GstPrice);
                           $item->setIgstPercent($gstPercent);
                     }

                     $item->setExclPrice($exckudingTax);

                     $item->save();
              }

        }
    }

我想检查小计。

1 个答案:

答案 0 :(得分:0)

我使用观察者得到了我自己问题的答案。

我得到了小计金额,并根据我放置条件的小计。

$order=$observer->getEvent()->getInvoice()->getOrder();

由于