2013-10-12 42 views
0

我正在使用Magento Comunity Edition 1.7.0.2。我必須通過傳遞它的lineitems,運輸方法,付款方式,地址和促銷(優惠券代碼)信息,通過Magento SOAP V2 API計算總計。我需要計算lineitems總數(基準價格,稅金,折扣,總排名)和Subtoatl,運費,折扣稅和總計。我已經通過使用法師嘗試了這個PHP腳本。我創建了一個報價對象,並通過應用運輸車規則(使用優惠券/無優惠券)獲得了所需的所有計算結果。Magento通過SOAP V2 API計算總數,但促銷規則不適用?

但問題是,當我感動的是代碼Magento的自定義SOAP API模型的方法,它是計算所有總量含稅但折扣並不適用於它。我也試過結帳/購物車對象,但沒有效果。我已經閱讀了一些Magento Apis沒有啓動Magento常規PHP會話的地方。 magento會話是否可以通過Api工作?

以下是代碼:

public function getTotals($data) 
    { 
      $shipping_method = $data->shipment_method; 
      $payment_method = $data->payment_method; 
      $total_qty = 0; 
      $quote = Mage::getModel('sales/quote'); 


      if($data->customer->email!="") 
      { 
       $customer_email = $data->customer->email; 
       $customer = Mage::getModel("customer/customer"); 
       $customer->setWebsiteId(Mage::app()->getWebsite()->getId()); 
       $customer->loadByEmail($customer_email); //load customer by email id 
       $quote->assignCustomer($customer); 
      } 


      foreach($data->lineitems as $p) 
      { 
       $product = Mage::getModel('catalog/product'); 
       $product->load($product->getIdBySku($p->SKU)); 
       $qty = $p->QTY; 
       $buyInfo = array('qty' => $qty); 
       $total_qty += $p->QTY; 
       $quote->addProduct($product, new Varien_Object($buyInfo)); 
      } 


         $billingAddress = array(
      'firstname' => $data->billing_address->FirstName, 
      'lastname' => $data->billing_address->LastName, 
      'company' => $data->billing_address->CompanyName, 
      'email' => $data->billing_address->Email, 
      'street' => array(
      $data->billing_address->Address1, 
      $data->billing_address->Address2 
      ), 
      'city' => $data->billing_address->City, 
      'region_id' => $data->billing_address->FirstName, 
      'region' => $data->billing_address->Region, 
      'postcode' => $data->billing_address->PostalCode, 
      'country_id' => $data->billing_address->CountryId, 
      'telephone' => $data->billing_address->Telephone, 
      'fax' => $data->billing_address->Fax, 
      'customer_password' => '', 
      'confirm_password' => '', 
      'save_in_address_book' => '0', 
      'use_for_shipping' => '0', 
      ); 

      $shippingAddress = array(
      'firstname' => $data->shipping_address->FirstName, 
      'lastname' => $data->shipping_address->LastName, 
      'company' => $data->shipping_address->CompanyName, 
      'email' => $data->shipping_address->Email, 
      'street' => array(
      $data->shipping_address->Address1, 
      $data->shipping_address->Address2 
      ), 
      'city' => $data->shipping_address->City, 
      'region_id' => $data->shipping_address->RegionId, 
      'region' => $data->shipping_address->Region, 
      'postcode' => $data->shipping_address->PostalCode, 
      'country_id' => $data->shipping_address->CountryId, 
      'telephone' => $data->shipping_address->Telephone, 
      'fax' => $data->shipping_address->Fax, 
      'customer_password' => '', 
      'confirm_password' => '', 
      'save_in_address_book' => '0', 
      'use_for_shipping' => '0', 
      ); 



      $quote->getBillingAddress() 
      ->addData($billingAddress); 



       //$quote->setCouponCode($data->coupons[0]->coupanCode); 


      $quote->getShippingAddress() 
      ->addData($shippingAddress) 
      ->setShippingMethod($shipping_method) 
      ->setPaymentMethod($payment_method); 

      Mage::getSingleton('checkout/cart') 
      ->setQuote($quote); 



      Mage::getSingleton('checkout/cart') 
      ->getQuote() 
      ->getShippingAddress() 
      ->setCollectShippingRates(true); 

      Mage::getSingleton('checkout/cart') 
      ->getQuote() 
      ->setCouponCode(strlen($data->coupons[0]->coupanCode) ? $data->coupons[0]->coupanCode : '') 
      ->collectTotals() 
      ->save(); 

      $items = Mage::getSingleton('checkout/cart')->getItems(); 

,當我試圖讓折扣和應用規則的ID,我什麼也沒得到:(

$discount = $item->getDiscountAmount(); 
$apply_rule_id = $item->getAppliedRuleIds(); 

回答

0

我有點困惑您的問題,就像你提到的V2 API一樣,但是你的代碼示例都不包含SOAP請求。

這就是說,我的第一個猜測是你沒有爲API請求設置商店ID,cart_store_id字段。

如果不透露任何我想創建通過API報價,然後通過本地PHP,然後DIFF在數據庫中的結果看到本地PHP報價/訂單具有該API什麼額外的字段創建報價/訂單不

此外,追查

app/code/core/Mage/Checkout/Model/Cart/Api.php 
app/code/core/Mage/Checkout/Model/Cart/Api/V2.php 

的API請求,看看什麼叫可能會丟失可能是一個有益的做法也是如此。

+0

對不起,不是具體的。我使用一個自定義Api來計算總數,並從您的答案我得到一個暗示,我錯過了商店ID。由於哪個折扣不適用。現在它的工作。謝謝艾倫:) – MMQK