2017-06-17 24 views
1

通過邏輯掛鉤我試圖在發票保存後更新我的產品字段。在SuiteCRM中的發票邏輯掛鉤中獲取行項目

到目前爲止,我所瞭解的是,我需要獲取與AOS_Products_Quotes有關的發票,並從那裏獲得產品,更新必填字段並保存產品。那個聽起來是對的嗎?

邏輯掛鉤正在觸發,但關係不會加載。

function decrement_stocks ($bean, $event, $arguments) { 
    //$bean->product_value_c = $bean->$product_unit_price * $bean->product_qty; 

    $file = 'custom/modules/AOS_Invoices/decrement.txt'; 

    // Get the Invoice ID: 
    $sInvoiceID = $bean->id; 
    $oInvoice = new AOS_Invoices(); 
    $oInvoice->retrieve($sInvoiceID); 
    $oInvoice->load_relationship('aos_invoices_aos_product_quotes'); 
    $aProductQuotes = $oInvoice->aos_invoices_aos_product_quotes->getBeans(); 

    /* 
    $aLineItemslist = array(); 
    foreach ($oInvoice->aos_invoices_aos_product_quotes->getBeans() as $lineitem) { 
     $aLineItemslist[$lineitem->id] = $lineitem; 
    } 
    */ 
    $sBean = var_export($bean, true); 
    $sInvoice = var_export($oInvoice, true); 
    $sProductQuotes = var_export($aProductQuotes, true); 

    $current = $sProductQuotes . "\n\n\n------\n\n\n" . $sInvoice . "\n\n\n------\n\n\n" . $sBean; 

    file_put_contents($file, $current); 

    } 

發票正在檢索就好。但是load_relationship沒有做任何事情($ sInvoice沒有更改,也沒有更改)並且$aProductQuotes爲空。

我正在使用SuiteCRM 7.8.3,並在7.9.1上嘗試過,但沒有成功。我究竟做錯了什麼?

回答

0

我不熟悉SuiteCRM細節,但是我總是建議檢查:

  • 檢索()的返回值:豆或? 如果null,則沒有找到具有給定ID的bean。 在這種情況下$ oInvoice會留下空(您的意見建議,這裏的情況並非如此,雖然)

  • load_relationship()的返回值:(成功)或(失敗,檢查日誌)

我在想,爲什麼不使用$ bean?

相反,您似乎收到$ bean的另一個副本/引用(並將其稱爲$ oInvoice)?爲什麼? 還是你的意思是收到一個不同類型的 bean,它以某種方式連接到$ bean?

那麼它肯定沒有相同的id作爲$ bean,除非您專門爲此編碼。