Skip to content

Commit

Permalink
Module upgrade to work with Magento 2.2 - Note: Custom option dynamic…
Browse files Browse the repository at this point in the history
… pricing is overridden with this approach
  • Loading branch information
adammprost committed May 31, 2018
1 parent d144b3a commit 8a81cbc
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
@@ -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>
@@ -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>

2 comments on commit 8a81cbc

@waymanxie
Copy link

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!

@parchmntpress
Copy link

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!

Please sign in to comment.