n_oct/plugins/romanah/bagisto/components/Seller.php

111 lines
3.5 KiB
PHP
Raw Normal View History

2023-08-25 21:39:39 +00:00
<?php
namespace Romanah\Bagisto\Components;
use Cms\Classes\ComponentBase;
// use Illuminate\Support\Facades\Http;
use October\Rain\Network\Http;
use Redirect;
use Flash;
use Session as SessionP;
use RainLab\Translate\Models\Message;
class Seller extends ComponentBase
{
public function componentDetails()
{
return [
'name' => 'Seller',
'description' => 'Seller functions'
];
}
function onCreateSellerProd()
{
$dataInput = post();
$response = Http::post('https://nurgul.com.tm/app/api/seller/create/product', function ($http) use($dataInput) {
// $http->header('Content-Type', 'application/json');
$http->header('Accept', 'application/json');
// $data = $dataProd;
$data = [
$http->data("type", "simple"),
$http->data("marketplace_seller_id", $dataInput["seller_id"]),
$http->data("user", 'romanah_'),
$http->data("password", 'bt110226$$'),
2023-08-26 07:00:32 +00:00
$http->data("sku", \Str::slug($dataInput["sku"])),
2023-08-25 21:39:39 +00:00
];
$http->setOption(CURLOPT_POSTFIELDS, json_encode($data));
});
$dataqq = json_decode($response);
2023-08-26 07:00:32 +00:00
if (isset($dataqq->status) && $dataqq->status == 200) {
2023-08-26 06:45:56 +00:00
Flash::success(Message::trans('success.add.prod'));
return Redirect::to('/seller/product/update/'.$dataqq->data->id);
} elseif (!isset($dataqq->status)) {
Flash::error(Message::trans('error'));
return redirect()->refresh();
}
2023-08-25 21:39:39 +00:00
return $dataqq;
}
function onUpdateSellerProd()
{
$dataInput = post();
2023-08-26 06:45:56 +00:00
// dd($dataInput["status"]);
2023-08-25 21:39:39 +00:00
$response = Http::post('https://nurgul.com.tm/app/api/seller/update/product', function ($http) use($dataInput) {
// $http->header('Content-Type', 'application/json');
$http->header('Accept', 'application/json');
// $data = $dataProd;
$data = [
$http->data("product_id", $this->param("id")),
$http->data("user", 'romanah_'),
$http->data("password", 'bt110226$$'),
$http->data("sku", 'skuq'),
$http->data("channels", "Nurgul"),
$http->data("short_description", $dataInput["short_description"]), //
$http->data("description", $dataInput["description"]), //
$http->data("name", $dataInput["name"]), //
$http->data("url_key", \Str::slug($dataInput["name"])),
$http->data("new", 1),
$http->data("featured", $dataInput["featured"]),//
$http->data("visible_individually", 1),
2023-08-26 06:45:56 +00:00
$http->data("status", $dataInput["stat"]),//
2023-08-25 21:39:39 +00:00
$http->data("product_number", $dataInput["product_number"]), //
$http->data("price", $dataInput["price"]),//
$http->data("special_price", $dataInput["special_price"]),//
$http->data("weight", 0),
$http->data("qty", $dataInput["qty"]),//
];
$http->setOption(CURLOPT_POSTFIELDS, json_encode($data));
});
$dataqq = json_decode($response);
if ($dataqq->status == 200) {
Flash::success(Message::trans('success.add.prod'));
return Redirect::to('/seller/products');
} elseif (empty($dataqq)) {
Flash::error(Message::trans('error'));
return redirect()->refresh();
}
return $dataqq;
}
}