2017-06-17 63 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,除非您专门为此编码。