Skip to content

Commit aa5b662

Browse files
authored
Merge pull request #11 from magefan/12322-codazon-theme-compatibility
12322 codazon theme compatibility
2 parents f13cf55 + ec1074f commit aa5b662

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magefan\ProductLabel\Plugin\Frontend\Codazon\ThemeLayoutPro\Helper;
10+
11+
use Magefan\ProductLabel\Model\Config;
12+
use Magefan\ProductLabel\Model\Parser\Html;
13+
14+
class Data
15+
{
16+
/**
17+
* @var Config
18+
*/
19+
protected $config;
20+
21+
/**
22+
* @param Config $config
23+
*/
24+
public function __construct(
25+
Config $config
26+
) {
27+
$this->config = $config;
28+
}
29+
30+
/**
31+
* @param $subject
32+
* @param $result
33+
* @param $product
34+
* @return mixed|string
35+
*/
36+
public function afterGetProductImageHtml($subject, $result, $product)
37+
{
38+
return ($result && $this->config->isEnabled())
39+
? $result . Html::COMMENT_PREFIX . $product->getId() . Html::COMMENT_SUFFIX
40+
: $result;
41+
}
42+
}

etc/frontend/di.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
<plugin name="wrap_gallery_image_with_mf_comments" type="Magefan\ProductLabel\Plugin\Frontend\Magento\Catalog\Block\Product\View\Gallery" sortOrder="10" disabled="false"/>
1818
</type>
1919

20-
<type name="MageSuite\ProductTile\Block\Tile\Container">
20+
<type name="MageSuite\ProductTile\Block\Tile\Container">
2121
<plugin name="add_mf_comments_to_mage_suite_product_tile" type="Magefan\ProductLabel\Plugin\Frontend\MageSuite\ProductTile\Block\Tile\Container" sortOrder="10" disabled="false"/>
2222
</type>
23+
24+
<type name="Codazon\ThemeLayoutPro\Helper\Data">
25+
<plugin name="add_mf_comments_to_codazon_theme_layout_pro_data_helper" type="Magefan\ProductLabel\Plugin\Frontend\Codazon\ThemeLayoutPro\Helper\Data" sortOrder="10" disabled="false"/>
26+
</type>
2327
</config>

view/frontend/templates/product/initLabel.phtml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@
2222
<?php $script = "
2323
require(['jquery'], function ($) {
2424
$('[data-gallery-role=gallery-placeholder]').on('gallery:loaded', function () {
25-
$(this).parent().find('.mf-label-container').prependTo('" . $escaper->escapeHtml($block->getConfig()->getProductPageContainerSelector()) . "')
25+
26+
let mfLabelContainer = $(this).parent().find('.mf-label-container');
27+
28+
if (!mfLabelContainer.length) {
29+
mfLabelContainer = $('.product.media .mf-label-container');
30+
}
31+
32+
if (mfLabelContainer.length) {
33+
mfLabelContainer.prependTo('" . $escaper->escapeHtml($block->getConfig()->getProductPageContainerSelector()) . "')
34+
}
2635
});
2736
});
2837
"; ?>

0 commit comments

Comments
 (0)