Skip to content

Commit

Permalink
reset to magenerds-master
Browse files Browse the repository at this point in the history
  • Loading branch information
klg committed Mar 6, 2019
1 parent e042e15 commit 0cd70f1
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 209 deletions.
21 changes: 14 additions & 7 deletions Block/AfterPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ class AfterPrice extends \Magento\Framework\View\Element\Template
protected $_helper;

/**
* @var \Magento\Catalog\Model\Product
* @var string
*/
protected $_product;
protected $_configurablePricesJson;

/**
* @var string
* @var \Magento\Framework\Registry
*/
protected $_configurablePricesJson;
protected $_registry;

/**
* Constructor
Expand All @@ -56,12 +56,12 @@ class AfterPrice extends \Magento\Framework\View\Element\Template
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magenerds\BasePrice\Helper\Data $helper,
\Magento\Catalog\Model\Product $product,
\Magento\Framework\Registry $registry,
array $data = []
){
$this->_scopeConfig = $context->getScopeConfig();
$this->_helper = $helper;
$this->_product = $product;
$this->_registry = $registry;
parent::__construct($context, $data);
}

Expand All @@ -82,14 +82,21 @@ public function isEnabled()
return $moduleEnabled && !empty($productAmount);
}

/**
* @return bool
*/
public function isConfigurable():bool {
return $this->getProduct()->getTypeId() == 'configurable';
}

/**
* Retrieve current product
*
* @return \Magento\Catalog\Model\Product
*/
public function getProduct()
{
return $this->_product;
return $this->_registry->registry('current_product');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function getBasePriceText(Product $product)
*/
public function getReferenceUnit(Product $product)
{
return $product->getAttributeText('baseprice_reference_unit');
return __($product->getAttributeText('baseprice_reference_unit'));
}

/**
Expand Down
135 changes: 0 additions & 135 deletions Model/Plugin/AfterPrice.php

This file was deleted.

3 changes: 0 additions & 3 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\Pricing\Render">
<plugin name="magenerds_baseprice_priceRender" type="Magenerds\BasePrice\Model\Plugin\AfterPrice" />
</type>
<type name="Magento\ConfigurableProduct\Block\Product\View\Type\Configurable">
<plugin name="magenerds_baseprice_configurablePriceRender" type="Magenerds\BasePrice\Model\Plugin\ConfigurablePrice" />
</type>
Expand Down
39 changes: 38 additions & 1 deletion view/frontend/templates/afterprice.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,41 @@
<div class="baseprice">
<?php echo $block->getBasePrice() ?>
</div>
<?php endif; ?>
<?php if ($block->isConfigurable()): ?>
<script type="text/javascript">
require(['jquery', 'jquery/ui', 'domReady!'], function($) {
$('body').on('updatePrice', function (e, data) {

var swatchWidget = $('.swatch-opt').data('mage-SwatchRenderer');
if(swatchWidget) {
var options = _.object(_.keys(swatchWidget.optionsMap), {});

swatchWidget.element.find('.' + swatchWidget.options.classes.attributeClass + '[option-selected]').each(function () {
options[$(this).attr('attribute-id')] = $(this).attr('option-selected');
});
result = swatchWidget.options.jsonConfig.optionPrices[_.findKey(swatchWidget.options.jsonConfig.index, options)];
} else {
var configurableWidget = $('#product_addtocart_form').data('mage-configurable');

var options = {};

configurableWidget.element.find(configurableWidget.options.superSelector + ' option:selected').each(function () {
if($(this).val()) {
options[Number($(this).parent().prop('id').replace('attribute', ''))] = $(this).val();
}

});

var config = configurableWidget.option('spConfig');
result = config.optionPrices[_.findKey(config.index, options)];
}

var basePriceField = $('.product-info-price .baseprice');
if (typeof result != 'undefined' && result.magenerds_baseprice_text.length && basePriceField.length) {
basePriceField.html(result.magenerds_baseprice_text);
}
});
});
</script>
<?php endif; ?>
<?php endif; ?>
62 changes: 0 additions & 62 deletions view/frontend/templates/configurable/afterprice.phtml

This file was deleted.

0 comments on commit 0cd70f1

Please sign in to comment.