Skip to content
Code-Schnipsel Gruppen Projekte
Commit 7cfb8155 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

fix: quiqqer/products#263

Übergeordneter a26106fc
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
...@@ -25,18 +25,20 @@ function ($fields, $params) { ...@@ -25,18 +25,20 @@ function ($fields, $params) {
$fields = []; $fields = [];
} }
if (isset($params['order'])) { // if (isset($fields['order'])) {
$query['order'] = $params['order']; // $query['order'] = $fields['order'];
} // }
if (isset($params['limit'])) { if (isset($fields['limit'])) {
$query['limit'] = $params['limit']; $query['limit'] = $fields['limit'];
} }
$allowedFields = $Categories->getChildAttributes(); $allowedFields = $Categories->getChildAttributes();
$allowedFields = \array_flip($allowedFields); $allowedFields = \array_flip($allowedFields);
foreach ($fields as $field => $value) { $searchString = '';
foreach ($params as $field => $value) {
if (!isset($allowedFields[$field]) && $field != 'id') { if (!isset($allowedFields[$field]) && $field != 'id') {
continue; continue;
} }
...@@ -45,6 +47,20 @@ function ($fields, $params) { ...@@ -45,6 +47,20 @@ function ($fields, $params) {
'type' => '%LIKE%', 'type' => '%LIKE%',
'value' => $value 'value' => $value
]; ];
if ($field === 'fields') {
$query['where_or']['title_cache'] = [
'type' => '%LIKE%',
'value' => $value
];
$query['where_or']['description_cache'] = [
'type' => '%LIKE%',
'value' => $value
];
$searchString = $value;
}
} }
// search // search
...@@ -62,6 +78,16 @@ function ($fields, $params) { ...@@ -62,6 +78,16 @@ function ($fields, $params) {
return $a['title'] > $b['title']; return $a['title'] > $b['title'];
}); });
// all products at the beginning
$AllProducts = new \QUI\ERP\Products\Category\AllProducts();
if (!empty($searchString) && \stripos($AllProducts->getTitle(), $searchString) !== false) {
$allProducts = $AllProducts->getAttributes();
$allProducts['title'] = $AllProducts->getTitle();
\array_unshift($result, $allProducts);
}
return $result; return $result;
}, },
['fields', 'params'], ['fields', 'params'],
......
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
<field type="BIGINT(20) DEFAULT 0">parentId</field> <field type="BIGINT(20) DEFAULT 0">parentId</field>
<field type="TEXT NULL">fields</field> <field type="TEXT NULL">fields</field>
<field type="TEXT NULL">sites</field> <field type="TEXT NULL">sites</field>
<field type="TEXT NULL">title_cache</field>
<field type="TEXT NULL">description_cache</field>
<primary>id</primary> <primary>id</primary>
<auto_increment>id</auto_increment> <auto_increment>id</auto_increment>
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<event on="onTemplateGetHeader" fire="\QUI\ERP\Products\EventHandling::onTemplateGetHeader"/> <event on="onTemplateGetHeader" fire="\QUI\ERP\Products\EventHandling::onTemplateGetHeader"/>
<event on="onPermissionsSet" fire="\QUI\ERP\Products\EventHandling::onPermissionsSet"/> <event on="onPermissionsSet" fire="\QUI\ERP\Products\EventHandling::onPermissionsSet"/>
<event on="onRequest" fire="\QUI\ERP\Products\EventHandling::onRequest"/> <event on="onRequest" fire="\QUI\ERP\Products\EventHandling::onRequest"/>
<event on="onQuiqqerTranslatorPublish" fire="\QUI\ERP\Products\EventHandling::onQuiqqerTranslatorPublish"/>
<!-- package events --> <!-- package events -->
<event on="onPackageSetup" fire="\QUI\ERP\Products\EventHandling::onPackageSetup"/> <event on="onPackageSetup" fire="\QUI\ERP\Products\EventHandling::onPackageSetup"/>
......
...@@ -1179,4 +1179,64 @@ public static function onQuiqqerOrderSuccessful(QUI\ERP\Order\AbstractOrder $Ord ...@@ -1179,4 +1179,64 @@ public static function onQuiqqerOrderSuccessful(QUI\ERP\Order\AbstractOrder $Ord
} }
} }
} }
/**
* Update category title & description locale
*
* @throws QUI\Database\Exception
*/
public static function onQuiqqerTranslatorPublish()
{
$categoryTable = QUI\ERP\Products\Utils\Tables::getCategoryTableName();
$translationTable = QUI\Translator::table();
$catIds = QUI::getDataBase()->fetch([
'select' => 'id',
'from' => $categoryTable
]);
foreach ($catIds as $catId) {
try {
$title = '';
$desc = '';
// title
$titleResult = QUI::getDataBase()->fetch([
'from' => $translationTable,
'where' => [
'groups' => 'quiqqer/products',
'var' => 'products.category.'.$catId['id'].'.title'
],
'limit' => 1
]);
if (isset($titleResult[0])) {
$title = \json_encode($titleResult[0]);
}
// desc
$descResult = QUI::getDataBase()->fetch([
'from' => $translationTable,
'where' => [
'groups' => 'quiqqer/products',
'var' => 'products.category.'.$catId['id'].'.description'
],
'limit' => 1
]);
if (isset($descResult[0])) {
$desc = \json_encode($descResult[0]);
}
QUI::getDataBase()->update($categoryTable, [
'title_cache' => $title,
'description_cache' => $desc
], [
'id' => $catId['id']
]);
} catch (\Exception $Exception) {
QUI\System\Log::addError($Exception->getMessage());
}
}
}
} }
...@@ -45,7 +45,7 @@ public static function clearCache($categoryId = false) ...@@ -45,7 +45,7 @@ public static function clearCache($categoryId = false)
/** /**
* Returns the cache name of a category * Returns the cache name of a category
* *
* @param integer $categoryId * @param integer|string $categoryId
* @return string * @return string
*/ */
public static function getCacheName($categoryId) public static function getCacheName($categoryId)
...@@ -106,7 +106,7 @@ public static function getChildAttributes() ...@@ -106,7 +106,7 @@ public static function getChildAttributes()
} }
/** /**
* @param integer $id * @param integer|string $id
* @return QUI\ERP\Products\Interfaces\CategoryInterface * @return QUI\ERP\Products\Interfaces\CategoryInterface
* *
* @throws QUI\Exception * @throws QUI\Exception
...@@ -183,7 +183,7 @@ public static function getMainCategory() ...@@ -183,7 +183,7 @@ public static function getMainCategory()
/** /**
* Checks if a category exists * Checks if a category exists
* *
* @param integer $categoryId - category id * @param integer|string $categoryId - category id
* @return bool * @return bool
* @throws QUI\Exception * @throws QUI\Exception
*/ */
...@@ -228,7 +228,7 @@ public static function isCategory($Category) ...@@ -228,7 +228,7 @@ public static function isCategory($Category)
/** /**
* Create a new category * Create a new category
* *
* @param integer $parentId - optional, ID of the parent * @param integer|null|string $parentId - optional, ID of the parent
* @param string $title - optional, translation text for current language * @param string $title - optional, translation text for current language
* *
* @return QUI\ERP\Products\Interfaces\CategoryInterface * @return QUI\ERP\Products\Interfaces\CategoryInterface
...@@ -244,6 +244,8 @@ public static function createCategory($parentId = null, $title = '') ...@@ -244,6 +244,8 @@ public static function createCategory($parentId = null, $title = '')
$parentId = 0; $parentId = 0;
} }
$parentId = (int)$parentId;
$result = QUI::getDataBase()->fetch([ $result = QUI::getDataBase()->fetch([
'from' => QUI\ERP\Products\Utils\Tables::getCategoryTableName(), 'from' => QUI\ERP\Products\Utils\Tables::getCategoryTableName(),
'limit' => 1 'limit' => 1
...@@ -383,7 +385,7 @@ public static function getCategoryIds($queryParams = []) ...@@ -383,7 +385,7 @@ public static function getCategoryIds($queryParams = [])
} }
/** /**
* @param integer $id * @param integer|string $id
* @throws QUI\Exception * @throws QUI\Exception
*/ */
public static function deleteCategory($id) public static function deleteCategory($id)
......
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren