Skip to content

Commit 7c5c275

Browse files
committed
Merge remote-tracking branch 'ogre/MAGETWO-45280-cms-block-API-does-not-work' into SWAT-BugFixes-11Oct
2 parents e78190d + a6b6045 commit 7c5c275

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

app/code/Magento/Cms/Model/Block.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,14 @@ public function setIsActive($isActive)
214214
{
215215
return $this->setData(self::IS_ACTIVE, $isActive);
216216
}
217+
218+
/**
219+
* Receive page store ids
220+
*
221+
* @return int[]
222+
*/
223+
public function getStores()
224+
{
225+
return $this->hasData('stores') ? $this->getData('stores') : $this->getData('store_id');
226+
}
217227
}

app/code/Magento/Cms/Model/BlockRepository.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Framework\Reflection\DataObjectProcessor;
1616
use Magento\Cms\Model\ResourceModel\Block as ResourceBlock;
1717
use Magento\Cms\Model\ResourceModel\Block\CollectionFactory as BlockCollectionFactory;
18+
use Magento\Store\Model\StoreManagerInterface;
1819

1920
/**
2021
* Class BlockRepository
@@ -57,6 +58,11 @@ class BlockRepository implements BlockRepositoryInterface
5758
*/
5859
protected $dataBlockFactory;
5960

61+
/**
62+
* @var \Magento\Store\Model\StoreManagerInterface
63+
*/
64+
private $storeManager;
65+
6066
/**
6167
* @param ResourceBlock $resource
6268
* @param BlockFactory $blockFactory
@@ -65,6 +71,7 @@ class BlockRepository implements BlockRepositoryInterface
6571
* @param Data\BlockSearchResultsInterfaceFactory $searchResultsFactory
6672
* @param DataObjectHelper $dataObjectHelper
6773
* @param DataObjectProcessor $dataObjectProcessor
74+
* @param StoreManagerInterface $storeManager
6875
*/
6976
public function __construct(
7077
ResourceBlock $resource,
@@ -73,7 +80,8 @@ public function __construct(
7380
BlockCollectionFactory $blockCollectionFactory,
7481
Data\BlockSearchResultsInterfaceFactory $searchResultsFactory,
7582
DataObjectHelper $dataObjectHelper,
76-
DataObjectProcessor $dataObjectProcessor
83+
DataObjectProcessor $dataObjectProcessor,
84+
StoreManagerInterface $storeManager
7785
) {
7886
$this->resource = $resource;
7987
$this->blockFactory = $blockFactory;
@@ -82,6 +90,7 @@ public function __construct(
8290
$this->dataObjectHelper = $dataObjectHelper;
8391
$this->dataBlockFactory = $dataBlockFactory;
8492
$this->dataObjectProcessor = $dataObjectProcessor;
93+
$this->storeManager = $storeManager;
8594
}
8695

8796
/**
@@ -93,6 +102,8 @@ public function __construct(
93102
*/
94103
public function save(Data\BlockInterface $block)
95104
{
105+
$storeId = $this->storeManager->getStore()->getId();
106+
$block->setStoreId($storeId);
96107
try {
97108
$this->resource->save($block);
98109
} catch (\Exception $exception) {

app/code/Magento/Cms/Test/Unit/Model/BlockRepositoryTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ class BlockRepositoryTest extends \PHPUnit_Framework_TestCase
5353
*/
5454
protected $collection;
5555

56+
/**
57+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\StoreManagerInterface
58+
*/
59+
private $storeManager;
60+
5661
/**
5762
* Initialize repository
5863
*/
@@ -80,6 +85,14 @@ public function setUp()
8085
->disableOriginalConstructor()
8186
->setMethods(['create'])
8287
->getMock();
88+
$this->storeManager = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface')
89+
->disableOriginalConstructor()
90+
->getMock();
91+
$store = $this->getMockBuilder('\Magento\Store\Api\Data\StoreInterface')
92+
->disableOriginalConstructor()
93+
->getMock();
94+
$store->expects($this->any())->method('getId')->willReturn(0);
95+
$this->storeManager->expects($this->any())->method('getStore')->willReturn($store);
8396

8497
$this->block = $this->getMockBuilder('Magento\Cms\Model\Block')->disableOriginalConstructor()->getMock();
8598
$this->blockData = $this->getMockBuilder('Magento\Cms\Api\Data\BlockInterface')
@@ -121,7 +134,8 @@ public function setUp()
121134
$collectionFactory,
122135
$blockSearchResultFactory,
123136
$this->dataHelper,
124-
$this->dataObjectProcessor
137+
$this->dataObjectProcessor,
138+
$this->storeManager
125139
);
126140
}
127141

0 commit comments

Comments
 (0)