Skip to content

Commit 21f1956

Browse files
authored
Merge pull request #670 from magefan/release-2.13
Release 2.13
2 parents 20f5aab + 1cd00d6 commit 21f1956

25 files changed

+733
-1572
lines changed

Api/ManagementInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ public function delete($id);
4343
*
4444
* @api
4545
* @param int $id
46+
* @param int|null $storeId
4647
* @return bool
4748
*/
48-
public function get($id);
49+
public function get($id, $storeId = null);
4950

5051
/**
5152
* Get item by id and store id, only if item published

Model/AbstractManagement.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,20 @@ public function create($data)
114114
public function update($id, $data)
115115
{
116116
try {
117+
$data = json_decode($data, true);
117118
$item = $this->_itemFactory->create();
119+
120+
if (!empty($data['store_id'])) {
121+
$item->setStoreId((int)$data['store_id']);
122+
$item->setData('data_to_update', $data);
123+
}
124+
118125
$item->load($id);
119126

120127
if (!$item->getId()) {
121128
return $this->getError('Item not found');
122129
}
123-
$data = json_decode($data, true);
130+
124131
foreach ($this->_imagesMap as $key) {
125132
if (empty($data[$key . '_name']) || empty($data[$key . '_content'])) {
126133
unset($data[$key . '_name']);
@@ -162,12 +169,18 @@ public function delete($id)
162169
* Get item by id
163170
*
164171
* @param int $id
172+
* @param int|null $storeId
165173
* @return bool
166174
*/
167-
public function get($id)
175+
public function get($id, $storeId = 0)
168176
{
169177
try {
170178
$item = $this->_itemFactory->create();
179+
180+
if ($storeId) {
181+
$item->setStoreId((int)$storeId);
182+
}
183+
171184
$item->load($id);
172185

173186
if (!$item->getId()) {
@@ -190,6 +203,11 @@ public function view($id, $storeId)
190203
{
191204
try {
192205
$item = $this->_itemFactory->create();
206+
207+
if ($storeId) {
208+
$item->setStoreId((int)$storeId);
209+
}
210+
193211
$item->getResource()->load($item, $id);
194212

195213
if (!$item->isVisibleOnStore($storeId)) {

Model/AuthorRepository.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ public function getById($authorId, $editMode = false, $storeId = null, $forceRel
128128
$cacheKey = implode('_', func_get_args());
129129
if (!isset($this->instances[$cacheKey])) {
130130
$author = $this->authorFactory->create();
131+
132+
if ($storeId) {
133+
$author->setStoreId($storeId);
134+
}
135+
131136
$this->authorResourceModel->load($author, $authorId);
132137
if (!$author->getId()) {
133138
throw new NoSuchEntityException(__('Requested item doesn\'t exist'));

Model/CategoryRepository.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ public function getById($categoryId, $editMode = false, $storeId = null, $forceR
127127
$cacheKey = implode('_', func_get_args());
128128
if (!isset($this->instances[$cacheKey])) {
129129
$category = $this->categoryFactory->create();
130+
131+
if ($storeId) {
132+
$category->setStoreId($storeId);
133+
}
134+
130135
$this->categoryResourceModel->load($category, $categoryId);
131136
if (!$category->getId()) {
132137
throw new NoSuchEntityException(__('Requested item doesn\'t exist'));

Model/PostRepository.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,13 @@ public function save(Post $post)
120120
public function getById($postId, $editMode = false, $storeId = null, $forceReload = false)
121121
{
122122
$post = $this->postFactory->create();
123+
124+
if ($storeId) {
125+
$post->setStoreId($storeId);
126+
}
127+
123128
$this->postResourceModel->load($post, $postId);
129+
124130
if (!$post->getId()) {
125131
throw new NoSuchEntityException(__('Requested item doesn\'t exist'));
126132
}

Model/ResourceModel/Category.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,12 @@ public function lookupStoreIds($categoryId, $useCache = true)
284284

285285
return [];
286286
}
287+
288+
/**
289+
* @return string
290+
*/
291+
public function getEntityType()
292+
{
293+
return 'category';
294+
}
287295
}

Model/ResourceModel/Category/Collection.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313
*/
1414
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
1515
{
16+
/**
17+
* @inheritDoc
18+
*/
19+
protected $_eventPrefix = 'mfblog_category_collection';
20+
21+
/**
22+
* @inheritDoc
23+
*/
24+
protected $_eventObject = 'blog_category_collection';
25+
1626
/**
1727
* @inheritDoc
1828
*/

Model/ResourceModel/Post.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,4 +527,12 @@ protected function _lookupAll($postId, $tableName, $field)
527527

528528
return $adapter->fetchAll($select);
529529
}
530+
531+
/**
532+
* @return string
533+
*/
534+
public function getEntityType()
535+
{
536+
return 'post';
537+
}
530538
}

Model/ResourceModel/Post/Collection.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
2828
*/
2929
protected $_eventObject = 'blog_post_collection';
3030

31+
/**
32+
* @var string[]
33+
*/
34+
protected $_ftiCollumns = ['title', 'meta_keywords', 'meta_description', 'identifier', 'content'];
35+
3136
/**
3237
* @var \Magento\Store\Model\StoreManagerInterface
3338
*/
@@ -103,7 +108,6 @@ protected function _construct()
103108
$this->_map['fields']['store'] = 'store_table.store_id';
104109
$this->_map['fields']['category'] = 'category_table.category_id';
105110
$this->_map['fields']['tag'] = 'tag_table.tag_id';
106-
$this->_map['fields']['tag'] = 'tag_table.tag_id';
107111
$this->_map['fields']['relatedproduct'] = 'relatedproduct_table.related_id';
108112
}
109113

@@ -401,10 +405,7 @@ public function addSearchFilter($term)
401405
$tagPostIds = array_slice($tagPostIds, 0, 200);
402406
}
403407

404-
$fullExpression = '(0 ' .
405-
'+ FORMAT(MATCH (title, meta_keywords, meta_description, identifier, content) AGAINST ('
406-
. $this->getConnection()->quote($term)
407-
. '), 4) ' .
408+
$fullExpression = $this->getSearchRateExpression($term, $this->_ftiCollumns) .
408409
'+ IF(main_table.post_id IN (' . implode(',', $tagPostIds) . '), "1", "0"))';
409410

410411
$fullExpression = new \Zend_Db_Expr($fullExpression);
@@ -420,19 +421,25 @@ public function addSearchFilter($term)
420421
]
421422
);
422423

423-
$fullExpression = '(0 ' .
424-
'+ FORMAT(MATCH (title, meta_keywords, meta_description, identifier, content) AGAINST ('
425-
. $this->getConnection()->quote($term)
426-
. '), 4))';
427-
428-
$fullExpression = new \Zend_Db_Expr($fullExpression);
424+
$fullExpression = new \Zend_Db_Expr($this->getSearchRateExpression($term, $this->_ftiCollumns));
429425
$this->getSelect()->columns(['search_rate' => $fullExpression]);
426+
430427
//$this->expressionFieldsToSelect['search_rate'] = $fullExpression;
431428
}
432429

433430
return $this;
434431
}
435432

433+
/**
434+
* @param $term
435+
* @param array $columns
436+
* @return string
437+
*/
438+
public function getSearchRateExpression($term, array $columns): string
439+
{
440+
return '(0 + FORMAT(MATCH (' . implode(',', $columns) . ') AGAINST (' . $this->getConnection()->quote($term) . '), 4)) ';
441+
}
442+
436443
/**
437444
* Add tag filter to collection
438445
* @param array|int|string|\Magefan\Blog\Model\Tag $tag

Model/ResourceModel/Tag.php

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,21 @@ protected function _beforeDelete(\Magento\Framework\Model\AbstractModel $object)
4848
*/
4949
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
5050
{
51-
$object->setTitle(
52-
trim(($object->getTitle()))
53-
);
54-
55-
$tag = $object->getCollection()
56-
->addFieldToFilter('title', $object->getTitle())
57-
->addFieldToFilter('tag_id', ['neq' => $object->getId()])
58-
->setPageSize(1)
59-
->getFirstItem();
60-
if ($tag->getId()) {
61-
throw new \Magento\Framework\Exception\LocalizedException(
62-
__('The tag is already exist.')
51+
if ($object->getTitle()) {
52+
$object->setTitle(
53+
trim(($object->getTitle()))
6354
);
55+
56+
$tag = $object->getCollection()
57+
->addFieldToFilter('title', $object->getTitle())
58+
->addFieldToFilter('tag_id', ['neq' => $object->getId()])
59+
->setPageSize(1)
60+
->getFirstItem();
61+
if ($tag->getId()) {
62+
throw new \Magento\Framework\Exception\LocalizedException(
63+
__('The tag is already exist.')
64+
);
65+
}
6466
}
6567

6668
$identifierGenerator = \Magento\Framework\App\ObjectManager::getInstance()
@@ -180,7 +182,7 @@ public function checkIdentifier($identifier, $storeIds)
180182
$select = $this->_getLoadByIdentifierSelect($identifier, $storeIds);
181183
$select->reset(\Zend_Db_Select::COLUMNS)->columns(['cp.tag_id', 'cp.identifier'])->order('cps.store_id DESC')->limit(1);
182184

183-
185+
184186

185187
$row = $this->getConnection()->fetchRow($select);
186188
if (isset($row['tag_id']) && isset($row['identifier'])
@@ -338,4 +340,12 @@ protected function _lookupAll($tagId, $tableName, $field)
338340

339341
return $adapter->fetchAll($select);
340342
}
343+
344+
/**
345+
* @return string
346+
*/
347+
public function getEntityType()
348+
{
349+
return 'tag';
350+
}
341351
}

0 commit comments

Comments
 (0)