public function init()
 {
     $this->name = \Yii::t('skeeks/shop/app', 'Elements');
     $this->modelShowAttribute = "name";
     $this->modelClassName = ShopCmsContentElement::className();
     parent::init();
 }
Exemple #2
0
    ?>
        <?php 
    foreach ($dataProvider->query->all() as $order) {
        ?>

            <?php 
        if ($order->products) {
            foreach ($order->products as $productData) {
                $v3toysId = \yii\helpers\ArrayHelper::getValue($productData, 'v3toys_product_id');
                $id = \yii\helpers\ArrayHelper::getValue($productData, 'product_id');
                $quantity = \yii\helpers\ArrayHelper::getValue($productData, 'quantity');
                $price = \yii\helpers\ArrayHelper::getValue($productData, 'price');
                /**
                 * @var $element \skeeks\cms\shop\models\ShopCmsContentElement
                 */
                if ($element = \skeeks\cms\shop\models\ShopCmsContentElement::findOne((int) $id)) {
                    $purchasingPrice = $purchasingPrice + $quantity * (double) $element->shopProduct->purchasing_price;
                } else {
                    $notFoundProducts++;
                }
            }
        }
        ?>

            <?php 
        $moneyPurchasing = \Yii::$app->money->newMoney((string) $purchasingPrice);
        $moneyTotal = $moneyTotal->add($order->money);
        $moneyTotalNoDelivery = $moneyTotalNoDelivery->add($order->moneyOriginal);
        ?>
        <?php 
    }
 /**
  * Returns the list of attribute names.
  * By default, this method returns all public non-static properties of the class.
  * You may override this method to change the default behavior.
  * @return array list of attribute names.
  */
 public function attributes()
 {
     $class = new \ReflectionClass($this);
     $names = [];
     foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
         if (!$property->isStatic()) {
             $names[] = $property->getName();
         }
     }
     return ArrayHelper::merge(parent::attributes(), $names);
 }
Exemple #4
0
 /**
  * Обновление цен и налчия товаров
  */
 public function actionProductsUpdate()
 {
     $contentIds = (array) \Yii::$app->v3toysSettings->content_ids;
     if (!$contentIds) {
         $this->stdout("Не настроен v3toys комонент: {$total}\n", Console::FG_RED);
         return;
     }
     $count = ShopCmsContentElement::find()->where(['content_id' => $contentIds])->count();
     $this->stdout("Всего товаров: {$count}\n", Console::BOLD);
     if ($count) {
         foreach (ShopCmsContentElement::find()->where(['content_id' => $contentIds])->each(10) as $element) {
             $this->stdout("\t{$element->id}: {$element->name}\n");
             $v3id = $element->relatedPropertiesModel->getAttribute(\Yii::$app->v3toysSettings->v3toysIdPropertyName);
             if ($v3id) {
                 $response = \Yii::$app->v3toysApi->getProductsDataByIds(['products_ids' => $v3id]);
                 $this->stdout("\t\tОтвет получен из api\n");
                 if ($response->isOk) {
                     if ($response->data) {
                         $data = $response->data[0];
                         $priceFromApi = (double) ArrayHelper::getValue($data, 'price');
                         $quantityFromApi = (int) ArrayHelper::getValue($data, 'quantity');
                         $isChange = false;
                         $ourPrice = $priceFromApi + $priceFromApi / 100 * \Yii::$app->v3toysSettings->price_discount_percent;
                         $ourPrice = round($ourPrice);
                         $discountValue = \Yii::$app->v3toysSettings->price_discount_percent;
                         $guiding_buy_price = (double) ArrayHelper::getValue($data, 'buy_price');
                         $mr_price = (double) ArrayHelper::getValue($data, 'mr_price');
                         if ($ourPrice > $guiding_buy_price) {
                             $this->stdout("\t\t{$priceFromApi} + {$discountValue}% = {$ourPrice}\n");
                         } else {
                             $ourPrice = $priceFromApi;
                             $this->stdout("\t\tНаша цена со скидкой {$ourPrice} < закупочной {$guiding_buy_price} оставим {$priceFromApi}\n");
                         }
                         if ($ourPrice < $mr_price) {
                             $ourPrice = $mr_price;
                             $this->stdout("\t\t MR PRICE = {$mr_price}\n", Console::FG_YELLOW);
                         }
                         if ($ourPrice != $element->shopProduct->baseProductPriceValue) {
                             $isChange = true;
                             $this->stdout("\t\tЦена изменилась была {$element->shopProduct->baseProductPriceValue} стала {$ourPrice}\n", Console::FG_GREEN);
                             $element->shopProduct->purchasing_price = ArrayHelper::getValue($data, 'buy_price');
                             $element->shopProduct->purchasing_currency = "RUB";
                             $element->shopProduct->baseProductPriceValue = $ourPrice;
                             $element->shopProduct->baseProductPriceCurrency = "RUB";
                         } else {
                             $this->stdout("\t\tЦена не менялась\n");
                         }
                         if ((int) ArrayHelper::getValue($data, 'quantity') != (int) $element->shopProduct->quantity) {
                             $isChange = true;
                             $this->stdout("\t\tИзменилось количество {$element->shopProduct->quantity} стало {$quantityFromApi}\n", Console::FG_GREEN);
                             $element->shopProduct->quantity = (int) ArrayHelper::getValue($data, 'quantity');
                         } else {
                             $this->stdout("\t\tКоличество не изменилось\n");
                         }
                         if ($isChange) {
                             if ($element->shopProduct->save()) {
                                 $this->stdout("\tДанные сохранены\n", Console::FG_GREEN);
                             } else {
                                 $error = Json::encode($element->shopProduct->errors);
                                 $this->stdout("\tДанные не сохранены {$error}\n", Console::FG_RED);
                             }
                         }
                     } else {
                         \Yii::error('Нет информации о товаре: ' . $element->id, self::className());
                         $this->stdout("\tInvalid api\n", Console::FG_RED);
                     }
                 } else {
                     $this->stdout("\tApi response bad\n", Console::FG_RED);
                     continue;
                 }
             } else {
                 $this->stdout("\t{$element->id}: {$element->name}\n", Console::FG_RED);
                 continue;
             }
         }
     }
 }
 /**
  * @param array $product
  * @return array|null|ShopCmsContentElement|\yii\db\ActiveRecord
  * @throws \skeeks\cms\relatedProperties\models\InvalidParamException
  */
 protected function _getCmsContentElementProduct($product = [])
 {
     $cmsContent = ShopCmsContentElement::find()->joinWith('relatedElementProperties map')->joinWith('relatedElementProperties.property property')->andWhere(['property.code' => \Yii::$app->v3toysSettings->v3toysIdPropertyName])->andWhere(['map.value' => ArrayHelper::getValue($product, 'external_id')])->joinWith('cmsContent as ccontent')->andWhere(['ccontent.code' => 'product'])->one();
     if (!$cmsContent) {
         $content = CmsContent::findOne(['code' => 'product']);
         //Иначе создадим
         $cmsContent = new ShopCmsContentElement();
         //$cmsContent->tree_id = ImportStockSaleV2::ROOT_TREE_ID; //Каталог
         $cmsContent->content_id = CmsContent::findOne(['code' => 'product'])->id;
         //Тип контента
         $cmsContent->name = ArrayHelper::getValue($product, 'name');
         if ($cmsContent->save()) {
             $cmsContent->relatedPropertiesModel->setAttribute(\Yii::$app->v3toysSettings->v3toysIdPropertyName, ArrayHelper::getValue($product, 'external_id'));
             $cmsContent->relatedPropertiesModel->save(false);
         } else {
             throw new Exception("Not created product: " . serialize($cmsContent->getFirstErrors()));
         }
         $this->stdout("\tCreated element {$cmsContent->id}\n");
         return $cmsContent;
     }
     $this->stdout("\tExist element {$cmsContent->id}\n");
     return $cmsContent;
 }
Exemple #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTradeOffers()
 {
     return $this->hasMany(ShopCmsContentElement::className(), ['parent_content_element_id' => 'id'])->orderBy(['priority' => SORT_ASC]);
 }
Exemple #7
0
 /**
  * @param $cmsElementId
  * @param int $quantity
  *
  * @return $this
  * @throws Exception
  */
 public function addProduct($cmsElementId, $quantity = 1)
 {
     /**
      * @var $shopElement ShopCmsContentElement
      */
     $shopElement = ShopCmsContentElement::findOne($cmsElementId);
     if (!$shopElement) {
         throw new Exception('Этот продукт не найден');
     }
     $products = [];
     $products[] = ['v3toys_product_id' => (int) $shopElement->relatedPropertiesModel->getAttribute(\Yii::$app->v3toysSettings->v3toysIdPropertyName), 'price' => $shopElement->shopProduct->baseProductPriceValue, 'quantity' => $quantity, 'name' => (string) $shopElement->name, 'product_id' => (int) $shopElement->id];
     $this->products = ArrayHelper::merge((array) $this->products, $products);
     return $this;
 }