modules/Products/actions/SubProducts.php
<?php
/* +***********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
* *********************************************************************************** */
class Products_SubProducts_Action extends \App\Controller\Action
{
/**
* Function to check permission.
*
* @param \App\Request $request
*
* @throws \App\Exceptions\NoPermittedToRecord
*/
public function checkPermission(App\Request $request)
{
$recordId = $request->getInteger('record');
if (!$recordId) {
throw new \App\Exceptions\NoPermittedToRecord('ERR_NO_PERMISSIONS_FOR_THE_RECORD', 406);
}
if (!\App\Privilege::isPermitted($request->getModule(), 'DetailView', $recordId)) {
throw new \App\Exceptions\NoPermittedToRecord('ERR_NO_PERMISSIONS_FOR_THE_RECORD', 406);
}
}
public function process(App\Request $request)
{
$productId = $request->getInteger('record');
$values = [];
if (\App\Record::isExists($productId)) {
$productModel = Vtiger_Record_Model::getInstanceById($productId);
$subProducts = $productModel->getSubProducts();
foreach ($subProducts as $subProduct) {
$values[$subProduct->getId()] = $subProduct->getName();
}
}
$response = new Vtiger_Response();
$response->setResult($values);
$response->emit();
}
}