Skip to content

Commit

Permalink
Merge pull request #141 from PrestaSafe/fix-id-0-fieldcore
Browse files Browse the repository at this point in the history
Fix id_lang and id_shop = 0
  • Loading branch information
PrestaSafe authored Sep 18, 2023
2 parents cade608 + 6c33740 commit f2fe6be
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
23 changes: 18 additions & 5 deletions classes/PrettyBlocksSettingsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
8 changes: 8 additions & 0 deletions classes/prettyblocks/core/FieldCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
Expand Down

0 comments on commit f2fe6be

Please sign in to comment.