Skip to content

Commit b373a34

Browse files
authored
Merge pull request #10 from landofcoder/feature2-1
add controller Save Tag
2 parents 0e20896 + a3f9f85 commit b373a34

File tree

20 files changed

+1333
-251
lines changed

20 files changed

+1333
-251
lines changed

Api/Data/TagInterface.php

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,29 @@
11
<?php
2-
/**
3-
* Copyright (c) 2019 Landofcoder
4-
*
5-
* Permission is hereby granted, free of charge, to any person obtaining a copy
6-
* of this software and associated documentation files (the "Software"), to deal
7-
* in the Software without restriction, including without limitation the rights
8-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
* copies of the Software, and to permit persons to whom the Software is
10-
* furnished to do so, subject to the following conditions:
11-
*
12-
* The above copyright notice and this permission notice shall be included in all
13-
* copies or substantial portions of the Software.
14-
*
15-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
* SOFTWARE.
22-
*/
23-
242
namespace Lof\ProductTags\Api\Data;
253

264
interface TagInterface extends \Magento\Framework\Api\ExtensibleDataInterface
275
{
286

297
const TAG_ID = 'tag_id';
308
const TAG_NAME = 'tag_name';
31-
32-
/**
33-
* Get tag_id
34-
* @return string|null
35-
*/
369
public function getTagId();
3710

38-
/**
39-
* Set tag_id
40-
* @param string $tagId
41-
* @return \Lof\ProductTags\Api\Data\TagInterface
42-
*/
4311
public function setTagId($tagId);
44-
45-
/**
46-
* Get tag_name
47-
* @return string|null
48-
*/
4912
public function getTagName();
50-
51-
/**
52-
* Set tag_name
53-
* @param string $tagName
54-
* @return \Lof\ProductTags\Api\Data\TagInterface
55-
*/
5613
public function setTagName($tagName);
5714

5815
/**
5916
* Retrieve existing extension attributes object or create a new one.
6017
* @return \Lof\ProductTags\Api\Data\TagExtensionInterface|null
6118
*/
62-
public function getExtensionAttributes();
63-
64-
/**
65-
* Set an extension attributes object.
66-
* @param \Lof\ProductTags\Api\Data\TagExtensionInterface $extensionAttributes
67-
* @return $this
68-
*/
69-
public function setExtensionAttributes(
70-
\Lof\ProductTags\Api\Data\TagExtensionInterface $extensionAttributes
71-
);
19+
// public function getExtensionAttributes();
20+
21+
// /**
22+
// * Set an extension attributes object.
23+
// * @param \Lof\ProductTags\Api\Data\TagExtensionInterface $extensionAttributes
24+
// * @return $this
25+
// */
26+
// public function setExtensionAttributes(
27+
// \Lof\ProductTags\Api\Data\TagExtensionInterface $extensionAttributes
28+
// );
7229
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Lof\ProductTags\Api;
8+
9+
/**
10+
* @api
11+
* @since 100.0.2
12+
*/
13+
interface ProductLinkManagementInterface
14+
{
15+
/**
16+
* Get products assigned to category
17+
*
18+
* @param int $productSku
19+
* @return \Lof\ProductTags\Api\Data\ProductTagLinkInterface[]
20+
*/
21+
public function getAssignedProducts($categoryId);
22+
23+
/**
24+
* Assign product to given categories
25+
*
26+
* @param string $tagId
27+
* @param int[] $productSku
28+
* @return bool
29+
* @since 101.0.0
30+
*/
31+
public function assignProductToCategories($productSku, $tagId);
32+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Lof\ProductTags\Block\Adminhtml\Tags;
8+
9+
class AssignProducts extends \Magento\Backend\Block\Template
10+
{
11+
/**
12+
* Block template
13+
*
14+
* @var string
15+
*/
16+
protected $_template = 'Lof_ProductTags::lof_producttags/tag/edit/assign_products.phtml';
17+
//protected $_template = 'Magento_Catalog::catalog/category/edit/assign_products.phtml';
18+
/**
19+
* @var \Magento\Catalog\Block\Adminhtml\Category\Tab\Product
20+
*/
21+
protected $blockGrid;
22+
23+
/**
24+
* @var \Magento\Framework\Registry
25+
*/
26+
protected $registry;
27+
28+
/**
29+
* @var \Magento\Framework\Json\EncoderInterface
30+
*/
31+
protected $jsonEncoder;
32+
33+
/**
34+
* AssignProducts constructor.
35+
*
36+
* @param \Magento\Backend\Block\Template\Context $context
37+
* @param \Magento\Framework\Registry $registry
38+
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
39+
* @param array $data
40+
*/
41+
public function __construct(
42+
\Magento\Backend\Block\Template\Context $context,
43+
\Magento\Framework\Registry $registry,
44+
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
45+
array $data = []
46+
) {
47+
$this->registry = $registry;
48+
$this->jsonEncoder = $jsonEncoder;
49+
parent::__construct($context, $data);
50+
}
51+
52+
/**
53+
* Retrieve instance of grid block
54+
*
55+
* @return \Magento\Framework\View\Element\BlockInterface
56+
* @throws \Magento\Framework\Exception\LocalizedException
57+
*/
58+
public function getBlockGrid()
59+
{
60+
if (null === $this->blockGrid) {
61+
$this->blockGrid = $this->getLayout()->createBlock(
62+
\Lof\ProductTags\Block\Adminhtml\Tags\Tab\Product::class,
63+
'tag.product.grid'
64+
);
65+
}
66+
return $this->blockGrid;
67+
}
68+
69+
/**
70+
* Return HTML of grid block
71+
*
72+
* @return string
73+
*/
74+
public function getGridHtml()
75+
{
76+
return $this->getBlockGrid()->toHtml();
77+
}
78+
79+
/**
80+
* @return string
81+
*/
82+
public function getProductsJson()
83+
{
84+
if($this->getTag()){
85+
$products = $this->getTag()->getProductsPosition();
86+
if (!empty($products)) {
87+
return $this->jsonEncoder->encode($products);
88+
}
89+
}
90+
return '{}';
91+
}
92+
93+
/**
94+
* Retrieve current category instance
95+
*
96+
* @return array|null
97+
*/
98+
public function getTag()
99+
{
100+
return $this->registry->registry('tag');
101+
}
102+
}

Block/Adminhtml/Tags/Edit/DeleteButton.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class DeleteButton extends GenericButton implements ButtonProviderInterface
1818
public function getButtonData()
1919
{
2020
$data = [];
21-
if ($this->getBlockId()) {
21+
if ($this->getTagId()) {
2222
$data = [
2323
'label' => __('Delete Tag'),
2424
'class' => 'delete',

Block/Adminhtml/Tags/Edit/GenericButton.php

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,32 @@
66
namespace Lof\ProductTags\Block\Adminhtml\Tags\Edit;
77

88
use Magento\Backend\Block\Widget\Context;
9-
use Magento\Cms\Api\BlockRepositoryInterface;
9+
use Lof\ProductTags\Api\TagRepositoryInterface;
1010
use Magento\Framework\Exception\NoSuchEntityException;
11+
use Lof\ProductTags\Model\TagFactory;
1112

1213
/**
1314
* Class GenericButton
1415
*/
1516
class GenericButton
1617
{
17-
/**
18-
* @var Context
19-
*/
2018
protected $context;
21-
22-
/**
23-
* @var BlockRepositoryInterface
24-
*/
25-
protected $blockRepository;
26-
27-
/**
28-
* @param Context $context
29-
* @param BlockRepositoryInterface $blockRepository
30-
*/
19+
protected $tagRepository;
20+
protected $TagFactory;
3121
public function __construct(
3222
Context $context,
33-
BlockRepositoryInterface $blockRepository
23+
TagFactory $TagFactory,
24+
TagRepositoryInterface $tagRepository
3425
) {
3526
$this->context = $context;
36-
$this->blockRepository = $blockRepository;
27+
$this->TagFactory = $TagFactory
28+
?: \Magento\Framework\App\ObjectManager::getInstance()->get(TagFactory::class);
29+
$this->tagRepository = $tagRepository;
3730
}
38-
39-
/**
40-
* Return CMS block ID
41-
*
42-
* @return int|null
43-
*/
44-
public function getBlockId()
31+
public function getTagId()
4532
{
4633
try {
47-
return $this->blockRepository->getById(
48-
$this->context->getRequest()->getParam('tag_id')
49-
)->getId();
34+
return $this->tagRepository->getById($this->context->getRequest()->getParam('tag_name'))->getId();
5035
} catch (NoSuchEntityException $e) {
5136
}
5237
return null;

Block/Adminhtml/Tags/Edit/SaveButton.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function getButtonData()
2727
'buttonAdapter' => [
2828
'actions' => [
2929
[
30-
'targetName' => 'cms_block_form.cms_block_form',
30+
'targetName' => 'lof_producttags_tag_form.lof_producttags_tag_form',
3131
'actionName' => 'save',
3232
'params' => [
3333
true,
@@ -61,7 +61,7 @@ private function getOptions()
6161
'buttonAdapter' => [
6262
'actions' => [
6363
[
64-
'targetName' => 'cms_block_form.cms_block_form',
64+
'targetName' => 'lof_producttags_tag_form.lof_producttags_tag_form',
6565
'actionName' => 'save',
6666
'params' => [
6767
true,
@@ -83,7 +83,7 @@ private function getOptions()
8383
'buttonAdapter' => [
8484
'actions' => [
8585
[
86-
'targetName' => 'producttags_tag_form.producttags_tag_form',
86+
'targetName' => 'lof_producttags_tag_form.lof_producttags_tag_form',
8787
'actionName' => 'save',
8888
'params' => [
8989
true,

0 commit comments

Comments
 (0)