diff --git a/CHANGELOG.md b/CHANGELOG.md index 29a52a9..46ea665 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ CHANGELOG ============== +1.0.12 +----------------- + * Доработки + 1.0.11 ----------------- * Ответное апи diff --git a/_ide/YiiApplication.php b/_ide/YiiApplication.php index 44b4d8a..7a277cf 100644 --- a/_ide/YiiApplication.php +++ b/_ide/YiiApplication.php @@ -6,12 +6,13 @@ * @date 16.07.2016 */ namespace yii\web; +use v3toys\skeeks\components\V3toysComponent; use v3toys\skeeks\components\V3toysSettings; use v3toys\skeeks\V3toysModule; /** - * @property V3toysModule $v3toys - * @property V3toysSettings $v3toysSettings + * @property V3toysComponent $v3toys + * @property V3toysSettings $v3toysSettings * * Class Application * @package yii\web diff --git a/components/V3toysComponent.php b/components/V3toysComponent.php new file mode 100644 index 0000000..f51e24d --- /dev/null +++ b/components/V3toysComponent.php @@ -0,0 +1,28 @@ + + * @link http://skeeks.com/ + * @copyright 2010 SkeekS (СкикС) + * @date 16.07.2016 + */ +namespace v3toys\skeeks\components; + +use yii\base\Component; + +/** + * Class V3toysComponent + * + * @package v3toys\skeeks\components + */ +class V3toysComponent extends Component +{ + /** + * @param $cmsContentElement + * + * @return int + */ + public function getV3toysIdByCmsElement($cmsContentElement) + { + return (int) $cmsContentElement->relatedPropertiesModel->getAttribute($this->v3toysIdPropertyName); + } +} diff --git a/components/V3toysSettings.php b/components/V3toysSettings.php index ba98003..50c4c47 100644 --- a/components/V3toysSettings.php +++ b/components/V3toysSettings.php @@ -400,4 +400,5 @@ public function getCurrentMinPickupPrice() print_r($response->data); } }*/ + } diff --git a/config/main-console.php b/config/main-console.php index d628888..8e7f64c 100644 --- a/config/main-console.php +++ b/config/main-console.php @@ -18,6 +18,11 @@ 'class' => 'v3toys\skeeks\components\V3toysSettings' ], + 'v3toys' => + [ + 'class' => 'v3toys\skeeks\components\V3toysComponent' + ], + 'i18n' => [ 'translations' => diff --git a/config/main.php b/config/main.php index 04a6621..8b90342 100644 --- a/config/main.php +++ b/config/main.php @@ -18,6 +18,11 @@ 'class' => 'v3toys\skeeks\components\V3toysSettings' ], + 'v3toys' => + [ + 'class' => 'v3toys\skeeks\components\V3toysComponent' + ], + 'i18n' => [ 'translations' => diff --git a/console/controllers/AgentsController.php b/console/controllers/AgentsController.php index 7f0f888..9d1c610 100644 --- a/console/controllers/AgentsController.php +++ b/console/controllers/AgentsController.php @@ -241,9 +241,9 @@ public function actionMessagesUpdate() /** * Отправка новых заказов в v3toys */ - public function actionSubmitNewOrders() + public function actionSubmitNewOrders($countDay = 3) { - if ($orders = V3toysOrder::find()->where(['v3toys_order_id' => null])->andWhere(['>=', 'created_at', time() - 3600*24])->all()) + if ($orders = V3toysOrder::find()->where(['v3toys_order_id' => null])->andWhere(['>=', 'created_at', time() - 3600*24*$countDay])->all()) { $totalOrders = count($orders); $this->stdout("Заказов к отправке в v3toys: {$totalOrders}\n", Console::BOLD); diff --git a/models/V3toysOrder.php b/models/V3toysOrder.php index 008d27b..48a6bd4 100644 --- a/models/V3toysOrder.php +++ b/models/V3toysOrder.php @@ -8,6 +8,7 @@ namespace v3toys\skeeks\models; use skeeks\cms\models\behaviors\HasJsonFieldsBehavior; +use skeeks\cms\models\CmsContentElement; use skeeks\cms\models\CmsUser; use skeeks\cms\models\forms\SignupForm; use skeeks\cms\shop\models\ShopBuyer; @@ -317,8 +318,11 @@ static public function createCurrent() { if ($shopBasket->product) { + $v3toys_id = \Yii::$app->v3toys->getV3toysIdByCmsElement($shopBasket->product->cmsContentElement); + $products[] = [ - 'v3toys_product_id' => (int) $shopBasket->product->cmsContentElement->relatedPropertiesModel->getAttribute(\Yii::$app->v3toysSettings->v3toysIdPropertyName), + 'v3toys_product_id' => $v3toys_id, + 'purchasing_price' => $shopBasket->product->purchasing_price, 'price' => $shopBasket->price, 'quantity' => $shopBasket->quantity, 'name' => (string) $shopBasket->product->cmsContentElement->name, @@ -528,8 +532,17 @@ public function getProductsForApi() { foreach ((array) $this->products as $productdata) { + if (!$v3toys_id = ArrayHelper::getValue($productdata, 'v3toys_product_id')) + { + $productId = ArrayHelper::getValue($productdata, 'product_id'); + if ($element = CmsContentElement::findOne($productId)) + { + $v3toys_id = \Yii::$app->v3toys->getV3toysIdByCmsElement($element); + } + } + $result[] = [ - 'product_id' => ArrayHelper::getValue($productdata, 'v3toys_product_id'), + 'product_id' => $v3toys_id, 'price' => ArrayHelper::getValue($productdata, 'price'), 'quantity' => ArrayHelper::getValue($productdata, 'quantity'), ];