Closed debindra closed 2 years ago
That's mean $page variable is undefined, please check if $page has value or not.
Here is full function.
public function inventoryList($sync = false, $page = 1)
{
if (InventItem::exists() && !$sync) {
if (Request()->query('keyword')) {
return InventItem::where('Product_Code', 'like', Request()->query('keyword'))->paginate(10);
} else {
return InventItem::paginate(10);
}
} else {
set_time_limit(0);
$products = ZohoManager::useModule('Products')->getModuleInstance()->getRecords(['page' => $page, 'per_page' => 200])->getResponseJSON();
if (count($products['data']) > 0) {
foreach ($products['data'] as $item) {
// if ($item['Product_Active'] == true) {
// $statusPrdouct = 'Active';
// }
// if($item['Product_Active'] == false) {
// $statusPrdouct = 'InActive';
// }
InventItem::updateOrCreate(['zoho_id' => $item['id']], [
// 'item_id' => $user['item_id'],
'zoho_id' => $item['id'],
'brand' => $item['Product_Brand'],
'Product_Code' => $item['Product_Code'],
'sku' => $item['Product_Code'],
'Product_Name' => $item['Product_Name'],
'status' => $item['Product_Active'],
// 'quantity' => $item['Qty_in_Stock'],
'description' => $item['Description'] ?? '--',
'item_type' => 'inventory items',
'unit' => $item['Unit_Price'],
'Manufacturer' => $item['Manufacturer'] ?? '--',
'brand' => $item['Manufacturer'] ?? '--',
'purchase_type' => $item['Purchase_Type'] ?? '--',
'Product_Category' => $item['Product_Category'] ?? '--',
'Item_Serial_Number' => $item['Item_Serial_Number'] ?? '--',
'photographed' => $item['Photographed'],
'Cost' => $item['Cost'],
'currency_symbol' => $item['$currency_symbol'],
'minimum_sale_price' => $item['Minimum_Sale_Price'] ?? '--',
'type' => $item['Type'] ?? '--',
'weight' => $item['Weight'] ?? '--',
'clarity' => $item['Clarity'] ?? '--',
'shape' => $item['Shape'] ?? '--',
'color' => $item['Color'] ?? '--',
// 'selling_price' => $user['selling_price'],
'stock_locations' => $item['Current_Location'],
'item_pictures' => $item['Record_Image'] ?? '--',
]);
}
if ($products['info']['more_records']) {
$page = $page + 1;
$this->inventoryList(1, $page);
$count = \DB::table('invent_items')->count();
return InventItem::paginate($count);
} else {
return InventItem::paginate(200);
}
}
}
}
try this $page ?? 1
on page param to check if $page is empty return first page
ZohoManager::useModule('Products')
->getModuleInstance()
->getRecords(['page' => $page ?? 1, 'per_page' => 200])
->getResponseJSON();
@aemaddin
Aha, ok that's because you working on PHP 7.3, so you can change it to
ZohoManager::useModule('Products')
->getModuleInstance()
->getRecords(['page' => $page ? $page : 1, 'per_page' => 200])
->getResponseJSON();
@aemaddin, Now it's working as I upgraded to php version 7.4.21. For above your code, I put static value as 1 as but it did not work on 7.3.
maybe you can put all your code in "if" statement to make sure that $page variable has value then you do your code without need to check on ZohoManager on PHP 7.3.
if($page) {
ZohoManager::useModule('Products')
->getModuleInstance()
->getRecords(['page' => $page, 'per_page' => 200])
->getResponseJSON();
}
Okay, will try.
Hi there,
I tried to run below code I'm getting error $products = ZohoManager::useModule('Products')->getModuleInstance()->getRecords(['page' => $page, 'per_page' => 200])->getResponseJSON();
Error
message: "Undefined offset: 1", exception: "ErrorException",…} exception: "ErrorException" file: "/Applications/MAMP/htdocs/yamron/vendor/zohocrm/php-sdk-archive/src/crm/api/response/CommonAPIResponse.php" line: 105 message: "Undefined offset: 1"
I'm using php 7.3.11 but for other team mate, working this code very well.
If you need more, plz let me know.