Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Module upgrade to work with Magento 2.2 - Note: Custom option dynamic…
… pricing is overridden with this approach
- Loading branch information
1 parent
d144b3a
commit 8a81cbc
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...e/MyCompany/ConfigurableProductPriceRanges/view/frontend/layout/catalog_category_view.xml
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,10 @@ | ||
<?xml version="1.0"?> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<body> | ||
<referenceBlock name="category.product.type.details.renderers.configurable"> | ||
<action method="setTemplate"> | ||
<argument name="template" xsi:type="string">MyCompany_ConfigurableProductPriceRanges::product/listing/renderer.phtml</argument> | ||
</action> | ||
</referenceBlock> | ||
</body> | ||
</page> |
53 changes: 53 additions & 0 deletions
53
...any/ConfigurableProductPriceRanges/view/frontend/templates/product/listing/renderer.phtml
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,53 @@ | ||
<?php | ||
/** @var $block \Magento\Swatches\Block\Product\Renderer\Listing\Configurable */ | ||
|
||
/** @var \Magento\Catalog\Model\Product $product */ | ||
$product = $block->getProduct(); | ||
|
||
/** @var \Magento\Framework\Json\Helper\Data $jsonHelper */ | ||
$jsonHelper = $this->helper('\Magento\Framework\Json\Helper\Data'); | ||
|
||
$minPrice = $product->getMinimalPrice(); | ||
$maxPrice = $product->getMaxPrice(); | ||
|
||
$priceRange = []; | ||
|
||
if ($minPrice != $maxPrice) { | ||
$priceRange['priceRange'] = [ | ||
'amount' => $minPrice . ' - ' . $maxPrice | ||
]; | ||
} | ||
?> | ||
<div class="swatch-opt-<?= /* @escapeNotVerified */ $block->getProduct()->getId() ?>"></div> | ||
<script> | ||
require([ | ||
'jquery', | ||
'jquery/ui', | ||
'Magento_Swatches/js/swatch-renderer', | ||
'Magento_Swatches/js/catalog-add-to-cart', | ||
'priceBox' | ||
], function ($) { | ||
var jsonConfig = <?= /* @escapeNotVerified */ $block->getJsonConfig() ?>; | ||
|
||
$('.swatch-opt-<?= /* @escapeNotVerified */ $block->getProduct()->getId() ?>').SwatchRenderer({ | ||
selectorProduct: '.product-item-details', | ||
onlySwatches: true, | ||
enableControlLabel: false, | ||
numberToShow: <?= /* @escapeNotVerified */ $block->getNumberSwatchesPerProduct() ?>, | ||
jsonConfig: jsonConfig, | ||
jsonSwatchConfig: <?= /* @escapeNotVerified */ $block->getJsonSwatchConfig() ?>, | ||
mediaCallback: '<?= /* @escapeNotVerified */ $block->getMediaCallback() ?>' | ||
}); | ||
|
||
var dataPriceBoxSelector = '[data-role=priceBox]', | ||
dataProductIdSelector = '[data-product-id=<?= $block->escapeHtml($block->getProduct()->getId()) ?>]', | ||
priceBoxes = $(dataPriceBoxSelector + dataProductIdSelector); | ||
|
||
priceBoxes.priceBox({ | ||
'priceConfig': { | ||
priceFormat: jsonConfig.priceFormat, | ||
prices: <?= $priceRange ? $jsonHelper->jsonEncode($priceRange) : 'jsonConfig.prices' ?> | ||
} | ||
}); | ||
}); | ||
</script> |
8a81cbc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module works great under ver2.2.6! Many thanks. But there's still something that i should share with you guys.
1)After i copy the files to the app/code folder, i run the "setup:upgrade" command.
2)Everything seems fine but my store goes down. The error is "XXX for security reason". Then i check the report in var/report folder, it says "Unable to retrieve deployment version of static files from the file system ..."
3)i run the "setup:static-content:deploy"
4)then my store is back to alive
Hope this help the other guys who would like to use this module. thank you adammprost!
8a81cbc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks so much for your work on this! I've implemented it on our M2.2.8 store and it's generally working as expected. However, we are making use of landing pages, and it only seems to apply to catalog / product list views. What approach should we use to make it more global in scope? (On pages, static blocks, landing pages). Thanks again!