В настоящее время у меня есть для каждого цикла, в котором я использую для извлечения всех значений инвентаря продукта, если значение ниже, чем установленная сумма, мне нужно отправить кому-то электронное письмо. Теперь, как мне подойти к этому, чтобы не взорвать несколько писем, а только одно?
Теперь у меня есть
$theme = \Theme::current();
$client = new GuzzleHttp\Client(); //GuzzleHttp\Client
$arr = [];
try {
$resultinventory = $client->request(
"GET", "api.call.hidden", [
'auth' => [
'asfasf',
'asfasf'
]
]);
$body = $resultinventory->getBody();
$body->seek(0);
$body->read(1024);
$inventory = json_decode($body, true);
foreach($inventory as $i) {
if ($i['quantityOnHand'] < 10) {
$resultproduct = $client->request(
"GET", "api.hidden". $i['productId'], [
'auth' => [
'asfasf',
'asfasf'
]
]);
$bod = $resultproduct->getBody();
$bod->seek(0);
$bod->read(1024);
$product = json_decode($bod, true);
array_push($arr, $product);
}
}
$emailSubject = "Location A has items running low on stock";
$emailContents = "Dear Operations Team, Location A is running low on these items:</br>"
Mail::to('asf@asf.com')->send(new \App\Mail\SendNotificationEmail($emailSubject, $emailContents, $theme));
\Log::info($arr);
} catch (\GuzzleHttp\Exception\ClientException $e) {
$err = $e->getResponse()->getBody()->getContents();
\Log::info($err);
return response()->json(['error' => $e->getResponse()->getBody()->getContents(), 'error_code' => $err]);
}
$this->info('storehub:call is working fine');
Примечание: я хочу, чтобы все значения из $arr
отображались в $emailContents
по порядку,так будет как;"Dear Operations team, Location A is running low on these items: 1) Product A, 2)Product B."
и так далее.
Структура массива:
array (
0 =>
array (
'id' => '5db29b6d31c391731239bbdf',
'name' => 'Diamond bracelet (sample)',
'tags' =>
array (
0 => 'female',
1 => 'jewelry',
),
'category' => 'Accessories',
'sku' => '1029EHW',
'priceType' => 'Fixed',
'unitPrice' => 190,
'cost' => 90,
'trackStockLevel' => true,
'isParentProduct' => false,
),
1 =>
array (
'id' => '5db29b6d31c391731239bbdb',
'name' => 'Long-sleeved shirt(sample)(M)',
'tags' =>
array (
0 => 'tops',
1 => 'cotton',
),
'category' => 'Women\'s Apparel',
'sku' => 'ABC1234-M',
'priceType' => 'Fixed',
'unitPrice' => 47.170000000000002,
'cost' => 20,
'trackStockLevel' => true,
'isParentProduct' => false,
'parentProductId' => '5db29b6d31c391731239bbd4',
'variationValues' =>
array (
0 =>
array (
'variantGroupId' => '5db29b6d31c391731239bbd5',
'value' => 'M',
),
),
),
)