Skip to content

Commit d51b4e0

Browse files
committed
finalize the creation and update
1 parent 0e8de86 commit d51b4e0

File tree

2 files changed

+64
-18
lines changed

2 files changed

+64
-18
lines changed

CmsSync/Model/Objectmodel/Api.php

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ public function getSource()
2929

3030
/**
3131
* get an array of block info
32-
* @param $blockId
32+
* @param $identifier
3333
* @return mixed
3434
*/
35-
public function getBlockInfo($blockId)
35+
public function getBlockInfo($identifier)
3636
{
37-
$modelBlock = Mage::getModel('cms/block')->load($blockId);
37+
$modelBlock = Mage::getModel('cms/block')->load($identifier, 'identifier');
3838

3939
return $modelBlock->getData();
4040

@@ -43,31 +43,73 @@ public function getBlockInfo($blockId)
4343

4444
/**
4545
* check if the block exists in remote
46-
* @param $data array
46+
* @param $identifier string
4747
* @return mixed
4848
*/
49-
public function checkBlockExists($data)
49+
public function checkForNewBlock($identifier)
5050
{
51-
$identifier = $data['identifier'];
52-
$storeIds = $data['storeIds'];
5351

54-
$collection = Mage::getModel('cms/block')->getCollection()
55-
->addFilter('identifier' , $identifier)
56-
->addFieldToFilter('block_id', array('in' => $storeIds));
5752

58-
Mage::log('identifier to search : ' . $identifier);
59-
Mage::log($storeIds);
60-
Mage::log($collection->getData());
61-
return $collection->getSize();
53+
$blockModel = Mage::getModel('cms/block')->load($identifier, 'identifier');
54+
55+
56+
if ($blockModel){
57+
58+
return false;
59+
}
60+
return true;
6261
}
6362

6463
/**
6564
* Create new block
6665
* @param $data
66+
* @return Mage_Core_Model_Abstract
6767
*/
6868
public function createBlock($data)
6969
{
70-
Mage::log($data);
70+
if (!empty($data)){
71+
72+
$staticBlock = array(
73+
'title' => $data['title'],
74+
'identifier' => $data['identifier'],
75+
'content' => $data['content'],
76+
'store_id' => $data['store_id'],
77+
'is_active' => $data['is_active']
78+
);
79+
80+
$blockModel = Mage::getModel("cms/block");
81+
82+
83+
$blockModel->setData($staticBlock);
84+
$result = $blockModel->save();
85+
return $result;
86+
}
87+
88+
return false;
89+
}
90+
91+
/**
92+
* Update static block
93+
* @param $data
94+
* @return $this|bool
95+
*/
96+
public function updateBlock($data)
97+
{
98+
$identifier = $data['identifier'];
99+
100+
$staticBlock = array(
101+
'title' => $data['title'],
102+
'content' => $data['content'],
103+
'is_active' => $data['is_active']
104+
);
105+
106+
$blockModel = Mage::getModel('cms/block')->load($identifier, 'identifier');
107+
108+
if($blockModel){
109+
$blockModel->addData($staticBlock)->save();
110+
return true;
111+
}
112+
return false;
71113

72114
}
73115

CmsSync/etc/api.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@
2222
</block_info>
2323
<block_is_new translate="title" module="calindiacon_cmssync">
2424
<title>Check if block is new</title>
25-
<method>checkBlockExists</method>
25+
<method>checkForNewBlock</method>
2626
</block_is_new>
2727
<block_create translate="title" module="calindiacon_cmssync">
28-
<title>Create new block</title>
29-
<mehtod>createBlock</mehtod>
28+
<title>Check if bsdlock is new</title>
29+
<method>createBlock</method>
3030
</block_create>
31+
<block_update translate="title" module="calindiacon_cmssync">
32+
<title>Update Block</title>
33+
<method>updateBlock</method>
34+
</block_update>
3135
<info translate="title" module="calindiacon_cmssync">
3236
<title>Retrieve cutomers data with addresses</title>
3337
<method>info</method>

0 commit comments

Comments
 (0)