-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
188 additions
and
1 deletion.
There are no files selected for viewing
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,12 @@ | ||
<?php | ||
|
||
namespace DevStone\UsageCalculator\Block\Adminhtml\Usage\Edit; | ||
use Magento\Backend\Block\Template; | ||
|
||
class Preview extends Template | ||
{ | ||
|
||
protected $_template = 'DevStone_UsageCalculator::usage/edit/preview.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
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 @@ | ||
<?php | ||
echo 'preview the usage '; | ||
?> | ||
<script> | ||
var customOptionsContainer = jQuery('div[data-index=custom_options]') | ||
|
||
customOptionsContainer.find('tr.data-row').each(function (elem) { | ||
|
||
} ); | ||
</script> |
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,83 @@ | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
define([ | ||
'underscore', | ||
'Magento_Ui/js/form/element/abstract', | ||
'uiRegistry', | ||
'ko' | ||
], function (_, Abstract, registry, ko) { | ||
'use strict'; | ||
|
||
return Abstract.extend({ | ||
defaults: { | ||
listens: { | ||
'${ $.provider }:data': 'dataChanged' | ||
}, | ||
links: { | ||
allData: '${ $.provider }:data' | ||
} | ||
}, | ||
calculatedPrice: ko.observable(), | ||
calculatedSize: ko.observable(), | ||
|
||
/** | ||
* Invokes initialize method of parent class, | ||
* contains initialization logic | ||
*/ | ||
initialize: function () { | ||
this._super(); | ||
this.selectedUsageOptions = []; | ||
this.dataChanged(this.allData); | ||
return this; | ||
}, | ||
|
||
selectedUsageOptionsChanged: function(changed) { | ||
var price = this.allData.price; | ||
var size_id = this.allData.size_id; | ||
for( var index in this.allData.usage.options ) { | ||
if (this.allData.usage.options[index].type !== 'drop_down') { | ||
continue | ||
} | ||
var selectedOption = this.selectedUsageOptions[index]() | ||
if ( ! selectedOption ) { | ||
this.calculatedPrice(''); | ||
return; | ||
} | ||
if ( ! selectedOption.price ) { | ||
continue; | ||
} | ||
if ( selectedOption.size_id && selectedOption.size_id !== '0') { | ||
size_id = selectedOption.size_id; | ||
} | ||
price *= parseFloat(selectedOption.price.replace(/,/g, '')) / 100; | ||
} | ||
var size = registry.get('index = size_id').indexedOptions[size_id].label; | ||
this.calculatedSize(size); | ||
this.calculatedPrice('$'+price.toFixed(2)); | ||
}, | ||
|
||
dataChanged: function( data ) { | ||
if ( ! this.selectedUsageOptions || ! data.usage || ! data.usage.options ) { | ||
return; | ||
} | ||
for( var i = this.selectedUsageOptions.length; i < data.usage.options.length; i++ ) { | ||
var ob = ko.observable(); | ||
ob.subscribe(this.selectedUsageOptionsChanged.bind(this)); | ||
this.selectedUsageOptions.push(ob) | ||
} | ||
}, | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
initObservable: function () { | ||
this._super() | ||
.observe(['content']); | ||
|
||
return this; | ||
} | ||
}); | ||
}); |
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,33 @@ | ||
|
||
<div class="admin__field-complex" style="margin: 0" css="$data.additionalClasses" attr="'data-index': index"> | ||
|
||
<div class="admin__field-complex-title" if="allData.price"> | ||
Preview | ||
</div> | ||
<div class="admin__field-complex-title" if="allData.price"> | ||
Base Price $<span text="allData.price"></span> | ||
</div> | ||
|
||
<div class="" | ||
each="data: allData.usage.options, as: 'option'" | ||
> | ||
<div class="admin__field" style="margin:0" if="option.type === 'drop_down'"> | ||
<div class="admin__field-label" style="text-align: left"> | ||
<label> | ||
<span text="option.title"></span> | ||
</label> | ||
</div> | ||
<div class="admin__field-control"> | ||
<select class="admin__control-select" data-bind="options: option.values, optionsCaption:'-- Please Select --',value: $parent.selectedUsageOptions[$index()], optionsText: function(item) {return item.title + ' (price * ' + item.price + '%)'}"> | ||
</select> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="admin__field-complex-title" if="calculatedPrice"> | ||
<br /> | ||
Calculated Price <span style="color:#DD6666;font-weight: bold;font-size:1.3em;" text="calculatedPrice"></span> | ||
<br /> | ||
Calculated Size <span style="color:#726866;font-weight: bold;font-size:1.1em;" text="calculatedSize"></span> | ||
</div> | ||
<br /> | ||
</div> |