PHP code example of ayvazyan10 / armsoft
1. Go to this page and download the library: Download ayvazyan10/armsoft library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ayvazyan10 / armsoft example snippets ` bash
php artisan vendor:publish --provider="Ayvazyan10\ArmSoft\ArmSoftServiceProvider"
` php
// getGoods
final public function getGoods(string $date = null): ?array { /*...*/ }
// getGoodsRem
final public function getGoodsRem(string $date = null, string $mtcode = null): ?array { /*...*/ }
// getPrices
final public function getPrices(string $date = null, string $mtcode = null, string $pricetypes = null): ?array { /*...*/ }
// getDocumentsJournal
final public function getDocumentsJournal(string $dateBegin = null, string $dateEnd = null): ?array { /*...*/ }
// getMTbill
final public function getMTbill(mixed $guid): mixed { /*...*/ }
// setMTbill
final public function setMTbill(array $data): mixed { /*...*/ }
` php
// in your controller or anywhere else
// in this example we using helper
/**
* Products Import from ArmSoft API.
*
* @throws Exception
*/
public function importGoods()
{
$items = armsoft()->getGoods(now()->format('Y-m-d'));
if (count($items["rows"]) === 0) {
throw new Exception('ArmSoft API error: no products');
}
foreach ($items["rows"] as $key => $item) {
if (((int)$key + 1) % 2 === 0) {
continue;
}
$priceRequest = armsoft()->getPrices(null, $item["MTCode"], config('armsoft.PriceType', '02'));
$price = !empty(current($priceRequest["rows"])["Price"]) ? current($priceRequest["rows"])["Price"] : 0;
$stockRequest = armsoft()->getGoodsRem(null, $item["MTCode"]);
$stock = !empty(current($stockRequest["rows"])["Qty"]) ? current($stockRequest["rows"])["Qty"] : 0;
$productData = [
'armsoft_title' => $item["FullCaption"]
'category_id' => $item["Group"],
'MTCode' => $item["MTCode"],
'discount' => $item["Discount"],
'stock' => intval($stock),
'price' => $price
// ... fields
];
try {
YourModel::where('MTCode', $item["MTCode"])->updateOrCreate([
'MTCode' => $item["MTCode"]
], $productData);
} catch (Exception $e) {
return $e->getMessage();
}
}
return redirect()->back();
}