Skip to content

Commit d1fa92a

Browse files
committed
initial commit for the module. the module prints json ld structured data in the pd (product page)
0 parents  commit d1fa92a

File tree

19 files changed

+968
-0
lines changed

19 files changed

+968
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
composer.lock
2+
vendor/

Api/ProductManagementInterface.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Copyright © All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Osaka\StructuredData\Api;
9+
10+
interface ProductManagementInterface
11+
{
12+
13+
/**
14+
* GET for Product api
15+
* @param string $param
16+
* @return string
17+
*/
18+
public function getProduct($param);
19+
}
20+

Block/Adminhtml/AdminProduct.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright © All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Osaka\StructuredData\Block\Adminhtml;
9+
10+
class AdminProduct extends \Magento\Backend\Block\Template
11+
{
12+
13+
/**
14+
* Constructor
15+
*
16+
* @param \Magento\Backend\Block\Template\Context $context
17+
* @param array $data
18+
*/
19+
public function __construct(
20+
\Magento\Backend\Block\Template\Context $context,
21+
array $data = []
22+
) {
23+
parent::__construct($context, $data);
24+
}
25+
26+
/**
27+
* @return string
28+
*/
29+
public function getAdminProduct()
30+
{
31+
//Your block code
32+
return __('Hello Developer! This how to get the storename: %1 and this is the way to build a url: %2', $this->_storeManager->getStore()->getName(), $this->getUrl('contacts'));
33+
}
34+
}
35+

Block/Product.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright © All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Osaka\StructuredData\Block;
8+
9+
use Magento\Backend\Block\Template\Context;
10+
use Magento\Catalog\Helper\Data;
11+
use Magento\Catalog\Block\Product\View;
12+
13+
class Product extends View
14+
{
15+
public function getStructuredJsonData(): string
16+
{
17+
$productBasicInformation = $this->getProduct();
18+
19+
$shortDescription = trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', urldecode(html_entity_decode(strip_tags($productBasicInformation['short_description']))))));
20+
21+
$structuredData = "{";
22+
$structuredData .= '"@context": "https://schema.org/",' . "\n\r";
23+
$structuredData .= '"@type": "Product",' . PHP_EOL;
24+
$structuredData .= '"name": "'.$productBasicInformation->getName().'",' . "\n\r";
25+
$structuredData .= '"sku": "'.$productBasicInformation->getSku().'",' . "\n\r";
26+
$structuredData .= '"description": "'.$shortDescription.'",' . "\n\r";
27+
$structuredData .= '"image": ["'.$productBasicInformation->getMediaConfig()->getMediaUrl($productBasicInformation->getImage()).'"]' . "\n\r";
28+
29+
$structuredData .= "}";
30+
31+
32+
33+
return $structuredData;
34+
}
35+
}

COPYING.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Copyright © 2024-present
2+
3+
This file is part of Osaka/StructuredData.
4+
5+
Osaka/StructuredData is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
Please see LICENSE.txt for the full text of GNU General Public License

Controller/Index/Index.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Osaka\StructuredData\Controller\Index;
4+
5+
use Magento\Framework\App\Action\HttpGetActionInterface;
6+
7+
class Index implements HttpGetActionInterface
8+
{
9+
10+
public function execute()
11+
{
12+
die( "module works" );
13+
}
14+
}

0 commit comments

Comments
 (0)