Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed Jul 7, 2024
1 parent 2ae54ef commit f028c75
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 5 deletions.
37 changes: 37 additions & 0 deletions src/migrations/m240704_163220_create_table__shop_product_model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* @author Semenov Alexander <[email protected]>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 28.08.2015
*/
use yii\db\Migration;

class m240704_163220_create_table__shop_product_model extends Migration
{
public function safeUp()
{
$tableName = 'shop_product_model';
$tableExist = $this->db->getTableSchema($tableName, true);
if ($tableExist) {
return true;
}

$tableOptions = null;
if ($this->db->driverName === 'mysql') {
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}

$this->createTable($tableName, [
'id' => $this->primaryKey(),

'created_at' => $this->integer(),

], $tableOptions);

$this->createIndex($tableName.'__created_at', $tableName, 'created_at');
}

public function safeDown()
{}
}
32 changes: 32 additions & 0 deletions src/migrations/m240704_163221_alter_table__shop_product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* @author Semenov Alexander <[email protected]>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 28.08.2015
*/

use yii\db\Migration;

class m240704_163221_alter_table__shop_product extends Migration
{
public function safeUp()
{
$tableName = 'shop_product';

$this->addColumn($tableName, "shop_product_model_id", $this->integer()->null()->comment("Связь с моделью"));

$this->createIndex("{$tableName}__shop_product_model_id", $tableName, "shop_product_model_id");

$this->addForeignKey(
"{$tableName}__shop_product_model_id", $tableName,
'shop_product_model_id', '{{%shop_product_model}}', 'id', 'SET NULL', 'SET NULL'
);
}

public function safeDown()
{
echo "m240411_142301__alter_table__shop_store cannot be reverted.\n";
return false;
}
}
23 changes: 18 additions & 5 deletions src/models/ShopProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
* @property double $rating_value
* @property integer $rating_count
* @property integer $brand_id
* @property integer|null $shop_product_model_id
* @property string $brand_sku
* @property integer|null $country_alpha2
*
Expand Down Expand Up @@ -86,6 +87,8 @@
* @property ShopTypePrice $shopTypePrices
*
*
* @property ShopProductModel $shopProductModel
*
* @property ShopProduct $shopProductWhithOffers Товар с предложениями для текущего товара
* @property ShopProduct[] $shopProductOffers Предложения для текущего товара
*
Expand All @@ -97,7 +100,7 @@
* @property boolean $isSubProduct
* @property string $weightFormatted
* @property string $WeightPerOneMeasure Вес за 1 единицу измерений (например 1 м2)
* @property string $WeightPerOneMeasureFormatted
* @property string $WeightPerOneMeasureFormatted
* @property string $lengthFormatted
* @property string $widthFormatted
* @property string $heightFormatted
Expand Down Expand Up @@ -476,6 +479,7 @@ public function rules()
'expiration_time',
'service_life_time',
'warranty_time',
'shop_product_model_id',
],
'integer',
],
Expand Down Expand Up @@ -743,6 +747,8 @@ function ($attribute) {

[['measure_matches_jsondata'], 'string'],
[['measure_matches_jsondata'], 'default', 'value' => null],

[['shop_product_model_id'], 'default', 'value' => null],
[
['measure_matches_jsondata'],
function () {
Expand Down Expand Up @@ -833,7 +839,7 @@ function ($attribute) {
$shopProductBarcode->barcode_type = ArrayHelper::getValue($barcodeData, 'barcode_type');

if (!$shopProductBarcode->validate($validateAttributes)) {
$this->addError($attribute, print_r($barcodeData, true) . " — некорректный штрихкод: ".Json::encode($shopProductBarcode->errors));
$this->addError($attribute, print_r($barcodeData, true)." — некорректный штрихкод: ".Json::encode($shopProductBarcode->errors));
return false;
}
}
Expand Down Expand Up @@ -944,6 +950,14 @@ public function getBrand()
{
return $this->hasOne(ShopBrand::class, ['id' => 'brand_id'])->from(['shopBrand' => ShopBrand::tableName()]);

}
/**
* @return ShopBrand
*/
public function getShopProductModel()
{
return $this->hasOne(ShopProductModel::class, ['id' => 'shop_product_model_id'])->from(['shopProductModel' => ShopProductModel::tableName()]);

}
/**
* @return CmsCountry|null
Expand Down Expand Up @@ -1465,7 +1479,6 @@ public function getShopFeedbacks()
}



/**
* @var null
*/
Expand Down Expand Up @@ -1574,12 +1587,12 @@ public function getWeightPerOneMeasure()
if ($this->measure_ratio == 0) {
return 0;
}

if ($this->measure_ratio == 1) {
return $this->weight;
}

return (float) ($this->weight / $this->measure_ratio);
return (float)($this->weight / $this->measure_ratio);
}
/**
* @return float
Expand Down
41 changes: 41 additions & 0 deletions src/models/ShopProductModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* @author Semenov Alexander <[email protected]>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 14.09.2015
*/

namespace skeeks\cms\shop\models;

use skeeks\cms\base\ActiveRecord;
use skeeks\modules\cms\money\models\Currency;

/**
* This is the model class for table "{{%shop_product}}".
*
* @property integer $id
* @property integer $created_at
*
* @property ShopProduct[] $shopProducts
*/
class ShopProductModel extends ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%shop_product_model}}';
}


/**
* @return \yii\db\ActiveQuery
*/
public function getShopProducts()
{
return $this->hasMany(ShopProduct::class, ['shop_product_model_id' => 'id']);
}

}

0 comments on commit f028c75

Please sign in to comment.