diff --git a/classes/PrettyBlocksSettingsModel.php b/classes/PrettyBlocksSettingsModel.php index 0ef8ffdd..7846d66c 100644 --- a/classes/PrettyBlocksSettingsModel.php +++ b/classes/PrettyBlocksSettingsModel.php @@ -66,13 +66,26 @@ public static function getProfileByTheme($theme_name, $id_shop) $collection->where('theme_name', '=', $theme_name); $collection->where('id_shop', '=', $id_shop); + if (!$collection->getFirst()) { + return self::generateFirstProfile($theme_name, $id_shop); + } + return $collection->getFirst(); } - // public static function generateFirstProfile() - // { - // $theme_name = Context::getContext()->shop->theme_name; - // $id_shop = Context::getContext()->shop->id; + public static function generateFirstProfile($theme_name = null, $id_shop = null) + { + if ($theme_name === null) { + $theme_name = Context::getContext()->shop->theme_name; + } + if ($id_shop === null) { + $id_shop = Context::getContext()->shop->id; + } + $prettyBlocksSettingsModel = new PrettyBlocksSettingsModel(); + $prettyBlocksSettingsModel->theme_name = $theme_name; + $prettyBlocksSettingsModel->id_shop = $id_shop; + $prettyBlocksSettingsModel->save(); - // } + return $prettyBlocksSettingsModel; + } } diff --git a/classes/prettyblocks/core/FieldCore.php b/classes/prettyblocks/core/FieldCore.php index ef36b679..49da5e8a 100644 --- a/classes/prettyblocks/core/FieldCore.php +++ b/classes/prettyblocks/core/FieldCore.php @@ -49,6 +49,14 @@ class FieldCore public function __construct($data = []) { $this->setAttributeS($data); + + if ($this->id_lang == 0) { + $this->id_lang = \Context::getContext()->language->id; + } + + if ($this->id_shop == 0) { + $this->id_shop = \Context::getContext()->shop->id; + } } /**