-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom module to fetch Top Header API Details
- Loading branch information
0 parents
commit 9768dd5
Showing
8 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Binstellar\TopHeaderMenuAPI\Api; | ||
|
||
interface CustomInterface | ||
{ | ||
|
||
/** | ||
* @return string | ||
**/ | ||
|
||
public function getList(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
namespace Binstellar\TopHeaderMenuAPI\Model; | ||
|
||
use Magento\Cms\Block\Block as cmsBlock; | ||
use Magento\Framework\Serialize\SerializerInterface; | ||
use DOMDocument; | ||
|
||
class TopHeaderMenuAPI implements \Binstellar\TopHeaderMenuAPI\Api\CustomInterface | ||
{ | ||
|
||
/** | ||
* @var SerializerInterface | ||
*/ | ||
private $serializer; | ||
|
||
|
||
|
||
public function __construct( | ||
cmsBlock $cmsblock, | ||
\Magento\Framework\Serialize\Serializer\Json $json | ||
) { | ||
$this->cmsblock = $cmsblock; | ||
$this->json = $json; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getList() | ||
{ | ||
|
||
$dom = new DOMDocument; | ||
$dom->loadHTML($this->getCmsBlock()); | ||
|
||
return $dom->textContent; | ||
|
||
} | ||
|
||
public function getCmsBlock() | ||
{ | ||
$cmsblock = $this->cmsblock->setBlockId('top-header')->toHtml(); | ||
return $cmsblock; | ||
} | ||
} | ||
|
||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
## Magento2 How to create custom REST API to fetch details of CMS Block | ||
|
||
> Magento2 Content Management System (CMS) Blocks also know as static blocks are used to store many dynamic information of the client which needs to be changed by client on regular bases. Same thing needs to be sometimes shared via Rest API. | ||
Wondering how to achieve that? Don't worry we have got the solution for it. | ||
|
||
> Install our module Binstellar/TopHeaderMenuAPI | ||
|
||
## Installation Steps | ||
|
||
Step 1 : Download the Zip file from Github & Unzip it | ||
Step 2 : Create a directory under app/code/Binstellar/TopHeaderMenuAPI | ||
Step 3 : Upload the files & folders from extracted package to app/code/Binstellar/TopHeaderMenuAPI | ||
Step 4 : Go to the Magento2 Root directory & run following commands | ||
|
||
php bin/magento setup:upgrade | ||
php bin/magento setup:di:compile | ||
php bin/magento setup:static-content:deploy -f | ||
php bin/magento cache:flush | ||
|
||
|
||
## Note : We have tested this option in Magento ver. 2.4.5-p1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<preference for="Binstellar\TopHeaderMenuAPI\Api\CustomInterface" type="Binstellar\TopHeaderMenuAPI\Model\TopHeaderMenuAPI"/> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> | ||
<module name="Binstellar_TopHeaderMenuAPI" setup_version="1.0.0"> | ||
</module> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0"?> | ||
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd"> | ||
<route method="GET" url="/V1/topheadermenu/"> | ||
<service class="Binstellar\TopHeaderMenuAPI\Api\CustomInterface" method="getList"/> | ||
<resources> | ||
<resource ref="anonymous"/> | ||
</resources> | ||
</route> | ||
</routes> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
\Magento\Framework\Component\ComponentRegistrar::register( | ||
\Magento\Framework\Component\ComponentRegistrar::MODULE, | ||
'Binstellar_TopHeaderMenuAPI', | ||
__DIR__ | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
XZXZX |