Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed May 6, 2024
1 parent 16ddb05 commit b8600af
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 57 deletions.
3 changes: 3 additions & 0 deletions src/CdekCheckoutModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class CdekCheckoutModel extends DeliveryCheckoutModel
*/
public $id;

public $dataAddress;
public $dataPrice;

public $name;
public $city;
public $address;
Expand Down
26 changes: 26 additions & 0 deletions src/CdekDeliveryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ class CdekDeliveryHandler extends DeliveryHandler
*/
public $cityFrom = 'Москва';


/**
* @var string
*/
public $account = '';

/**
* @var string
*/
public $secure = '';

/**
* @var string Можно выбрать страну, для которой отображать список ПВЗ
*/
Expand Down Expand Up @@ -64,6 +75,12 @@ public function rules()
return ArrayHelper::merge(parent::rules(), [
[['defaultCity'], 'string'],
[['cityFrom'], 'string'],

[['account'], 'required'],
[['secure'], 'required'],

[['account'], 'string'],
[['secure'], 'string'],
[['country'], 'string'],
[['isCalculatePrice'], 'integer'],
[['isRequiredSelectPoint'], 'integer'],
Expand All @@ -79,6 +96,9 @@ public function attributeLabels()
'isCalculatePrice' => "Рассчитывать цену по выбранному ПВЗ?",
'isRequiredSelectPoint' => "Для оформления заказа ПВЗ должен быть выбран обязательно?",

'account' => "Account/Идентификатор",
'secure' => "Secure password/Пароль",

/*'api_key' => "Ключ api",
'custom_city' => "Город",
Expand All @@ -96,6 +116,9 @@ public function attributeHints()
'defaultCity' => "Есди город не указан, то будет определен автоматически по координатам пользователя.",
'isCalculatePrice' => "Если выбрано нет, то цена за доставку не будет рассчитываться.",
'isRequiredSelectPoint' => "Если выбрано да - то без выбранного ПВЗ заказ оформить не получится. Если выбрано нет - то заказ можно оформить без выбора ПВЗ",

'account' => "Получить доступ по адресу: <a href='https://lk.cdek.ru/integration'>https://lk.cdek.ru/integration</a>",
'secure' => "Получить доступ по адресу: <a href='https://lk.cdek.ru/integration'>https://lk.cdek.ru/integration</a>",
]);
}

Expand All @@ -110,6 +133,9 @@ public function getConfigFormFields()
'class' => FieldSet::class,
'name' => 'Основные',
'fields' => [
'account',
'secure',

'defaultCity',
'cityFrom',
'country',
Expand Down
52 changes: 51 additions & 1 deletion src/controllers/CdekController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,66 @@

namespace skeeks\cms\shop\cdek\controllers;

use skeeks\cms\shop\cdek\CdekDeliveryHandler;
use skeeks\cms\shop\cdek\CdekService;
use skeeks\cms\shop\cdek\Service;
use skeeks\cms\shop\models\ShopDelivery;
use skeeks\cms\shop\models\ShopOrder;
use yii\web\Controller;
use yii\web\NotFoundHttpException;

/**
* Class AdminExportTaskController
* @package skeeks\cms\export\controllers
*/
class CdekController extends Controller
{
public $enableCsrfValidation = false;

public function actionMap()
{
return $this->renderPartial($this->action->id);
$deliveryId = \Yii::$app->request->get("delivery_id");
$shopDelivery = ShopDelivery::findOne((int)$deliveryId);
if (!$shopDelivery) {
throw new NotFoundHttpException("Не указан способ доставки!");
}

$order_id = \Yii::$app->request->get("order_id");
$shopOrder = ShopOrder::findOne((int)$order_id);
if (!$shopOrder) {
throw new NotFoundHttpException("Не казан заказ!");
}


return $this->renderPartial($this->action->id, [
'shopDelivery' => $shopDelivery,
'shopOrder' => $shopOrder,
]);
}

public function actionCalculate()
{
$deliveryId = \Yii::$app->request->get("delivery_id");
$shopDelivery = ShopDelivery::findOne((int)$deliveryId);
if (!$shopDelivery) {
throw new NotFoundHttpException("Доставка не найдена!");
}

$order_id = \Yii::$app->request->get("order_id");
$shopOrder = ShopOrder::findOne((int)$order_id);
if (!$shopOrder) {
throw new NotFoundHttpException("Не казан заказ!");
}

/**
* @var $handler CdekDeliveryHandler
*/
$handler = $shopDelivery->handler;


$service = new CdekService($handler->account, $handler->secure);


$service->process($_GET, file_get_contents('php://input'));
}
}
137 changes: 103 additions & 34 deletions src/views/cdek/map.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,85 @@
<?php
/**
* @var $this yii\web\View
*/
* @var $this yii\web\View
* @var $shopDelivery \skeeks\cms\shop\models\ShopDelivery
* @var $shopOrder \skeeks\cms\shop\models\ShopOrder
* @var $cdekHandler \skeeks\cms\shop\cdek\CdekDeliveryHandler
*/

$cdekHandler = $shopDelivery->handler;


$goods = [];
if ($shopOrder->shopOrderItems)
{
foreach ($shopOrder->shopOrderItems as $orderItem)
{
$weight = '2';
$width = '20';
$height = '20';
$length = '20';

if ($orderItem->shopProduct) {
if ($orderItem->shopProduct->weight) {
$weight = $orderItem->shopProduct->weight;
}
if ($orderItem->shopProduct->width) {
$width = round($orderItem->shopProduct->width/10);
}
if ($orderItem->shopProduct->length) {
$length = round($orderItem->shopProduct->length/10);
}
if ($orderItem->shopProduct->height) {
$height = round($orderItem->shopProduct->height/10);
}
}


for ($i = 1; $i <= (int) $orderItem->quantity; $i++) {
$goods[] = [
"weight" => $weight,
"length" => $length,
"width" => $width,
"height" => $height,
];
}

$widgetData = \Yii::$app->request->get("cdek");
}
}

//$widgetData = (array) \Yii::$app->request->get("cdek");
$widgetData = [
'apiKey' => \Yii::$app->yaMap->api_key,
'from' => $cdekHandler->cityFrom ? $cdekHandler->cityFrom : "Москва",
/*'from' => [
'code' => '184'
],*/
'defaultLocation' => $cdekHandler->defaultCity ? $cdekHandler->defaultCity : "Москва",
'servicePath' => \yii\helpers\Url::to(['calculate', 'delivery_id' => $shopDelivery->id, 'order_id' => $shopOrder->id]),
'goods' => $goods,
];
$parentWidgetId = \yii\helpers\ArrayHelper::getValue(\Yii::$app->request->get("options"), 'id');

$jsData = \yii\helpers\Json::encode(\yii\helpers\ArrayHelper::merge($widgetData, [
'link' => 'forpvz',
]));
$jsData = \yii\helpers\Json::encode($widgetData);
\Yii::$app->seo->countersContent = '';

?>
<style>
html, body {
margin: 0;
padding: 0;
}
html, body {
margin: 0;
padding: 0;
}
</style>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Пример работы виджета ПВЗ</title>
<script id="ISDEKscript" type="text/javascript" src="https://widget.cdek.ru/widget/widjet.js" charset="utf-8"></script>
<script src="https://cdn.jsdelivr.net/npm/@cdek-it/widget@3" type="text/javascript"></script>
<script src="https://cdn.jsdelivr.net/npm/@unocss/runtime" type="text/javascript"></script>
<link href="https://cdn.jsdelivr.net/npm/@unocss/reset/tailwind.min.css" rel="stylesheet">
<!--<script id="ISDEKscript" type="text/javascript" src="https://widget.cdek.ru/widget/widjet.js" charset="utf-8"></script>-->
</head>
<body>
<script type="text/javascript">
Expand All @@ -35,47 +90,61 @@
if (typeof window.parent.$ === 'undefined') {
console.log('no jquery');
window.parent.addEventListener('load', function () {
alert("В родительском окне нет нужной библиотеки jquery. Пожалуйста, сообщите разработчикам!")
alert("В родительском окне нет нужной библиотеки jquery. Пожалуйста, сообщите разработчикам!")
})
}


var jParentWidget = window.parent.$("#" + parentElementId);

var jsData2 = {
detailAddress: true,
choose: true,

//В виджете скрыты варианты доставки: курьер или ПВЗ.
hidedelt: true,
"root": 'cdek-map',

//В виджете скрыты фильтры для отображения ПВЗ
hidedress: true,
hidecash: true,
canChoose: true,
sender: true,

//В виджете скрыт фильтр для отображения ПВЗ с примеркой.
hidedress: true,

bymapcoord: false,
hidecash: false,
hidedelt: true,
detailAddress: true,
hideFilters: {
have_cashless: true,
have_cash: true,
is_dressing_room: true,
type: false,
},

apikey: "<?php echo \Yii::$app->yaMap->api_key; ?>",
hideDeliveryOptions: {
office: false,
door: true,
},

onChoose: function(wat) {
jParentWidget.trigger("select", {
'data' : wat,
onChoose(type, tariff, address) {
jParentWidget.trigger("select", {
'data': {
'type': type,
'tariff': tariff,
'address': address,
},
});
},
},

onCalculate(type, tariff, address) {
console.log(type);
console.log(tariff);
console.log(address);
},
};


Object.assign(jsData, jsData2);

var widjet = new ISDEKWidjet(jsData);
document.addEventListener('DOMContentLoaded', () => {
var widget = new window.CDEKWidget(jsData);
});



</script>

<div id="forpvz" style="height:500px;"></div>
<!--<div id="forpvz" style="height:500px;"></div>-->
<div id="cdek-map" class="w-full h-[600px]"></div>

</body>
</html>
Loading

0 comments on commit b8600af

Please sign in to comment.