-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculation.phtml
457 lines (406 loc) · 23 KB
/
calculation.phtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
<?php
$metalKey = 'metal_type';
$entityType = 'catalog_product';
$purityAttributeKey = 'metal_purity';
$ccKey = 'diamond_colour_clarity';
$currentProduct = $block->getCurrentProduct();
//$shipping_days = $block->getProductAttrValue('shipping_days');
$productId = $currentProduct->getId();
$productPrice = $currentProduct->getPrice();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$attributeSet = $objectManager->create('Magento\Eav\Api\AttributeSetRepositoryInterface');
//$current_product = $objectManager->create('\Magento\Catalog\Model\ProductRepository')->getById($product_id);
$attributeSetRepository = $attributeSet->get($currentProduct->getAttributeSetId());
$attribute_set_name = $attributeSetRepository->getAttributeSetName();
$discount_title = '';
/* if ($currentProduct->getSpecialPrice() != '') {
$obj = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Framework\App\ResourceConnection');
$connection = $obj->getConnection();
$sql = "SELECT * FROM c_offer_product where product_id='" . $currentProduct->getId() . "'";
$offerData = $connection->fetchRow($sql);
$themeTable = $obj->getTableName('c_offer');
$sql = "SELECT * FROM " . $themeTable . " WHERE id='" . $offerData['offer_id'] . "'";
$offerCollection = $connection->fetchRow($sql);
$discount_title = $offerCollection['title'];
} */
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$storeManager = $objectManager->get('Magento\Store\Model\StoreManagerInterface');
$currencyFactory = $objectManager->create('Magento\Directory\Model\CurrencyFactory');
$currencyCode = $storeManager->getStore()->getCurrentCurrencyCode();
$currency = $currencyFactory->create()->load($currencyCode);
$currencySymbol = $currency->getCurrencySymbol();
$fancyStonePrice = '';
$fancyYesNo = $currentProduct->getFancyStone();
if ($fancyYesNo == 1) {
$sqlFancy = "SELECT * FROM manage_fancystone WHERE product_id='" . $productId . "'";
$resultFancyStone = $connection->fetchRow($sqlFancy);
$FancyStoneData = unserialize($resultFancyStone['fancystone_data']);
if (count($FancyStoneData['price']) > 0) {
$fancyStonePrice = array_sum($FancyStoneData['price']);
}
}
$PriceBreakUpYesNo = $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue('sm_makingcharge/eviayesno/pdp');
$shipDateYesNo = $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue('sm_makingcharge/eviayesno/expec_ship_date');
?>
<?php //echo $discount_title; ?>
<?php if ($PriceBreakUpYesNo == 1): ?>
<div class="price_bifurcation">
<div class="panel-group price_breakup" id="pricepro">
<div class="panel">
<div class="panel-heading" role="tab" id="priceproids">
<h4 class="panel-title">
<a role="button" class="collapsed" data-toggle="collapse" data-parent="#pricepro" href="#priceproid" aria-expanded="true" aria-controls="priceproid">
View Price Breakup
</a>
</h4>
</div>
<div id="priceproid" class="collapse" role="tabpanel" aria-labelledby="priceproids">
<div class="panel-body">
<table class="itemPrichtml">
<tbody>
<tr >
<td class="border_bottom"><span>Metal</span></td>
<td rowspan="2">
+
</td>
<?php if ($attribute_set_name != 'Necklace' && $attribute_set_name != 'Bangel Size'): ?>
<td class="border_bottom">
<span>Diamond</span>
</td>
<td rowspan="2">
+
</td>
<?php endif; ?>
<?php if ($fancyYesNo == 1): ?>
<td class="border_bottom">
<span>Gemstone</span>
</td>
<td rowspan="2">
+
</td>
<?php endif; ?>
<td class="border_bottom">
<span>Making Charge</span>
</td>
<td rowspan="2">
<img src="http://jewellery.eviaglobal.com/purekarat/skin/frontend/rwd/astra/images/charges-plus.png">
</td>
<td class="border_bottom">
<span>GST</span>
</td>
</tr>
<tr class="itemPrichtmlPric">
<td id="metalTotalPrice"></td>
<?php if ($attribute_set_name != 'Necklace' && $attribute_set_name != 'Bangel Size'): ?>
<td id="diamondTotalPrice"></td>
<?php endif; ?>
<?php if ($fancyYesNo == 1): ?>
<td id="stoneTotalPrice"></td>
<?php endif; ?>
<td id="makingChargeTotal"></td>
<td id="vatTotal"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div><!-- panel-group -->
<?php endif; ?>
<!--
<div class="metalformation clearfix"> -->
<?php
$metalOptionIds = array();
$metalOptionIds = $block->getProductMetalOptions();
$metalOptionLabels = $block->getMetalOptions();
$purityOptionIds = array();
$purityOptionIds = $block->getProductPurityOptions();
$purityOptionLabels = $block->getPurityOptions();
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$sql1 = "SELECT * FROM sm_productprice WHERE product_id='" . $productId . "'";
$result = $connection->fetchAll($sql1);
if (count($result)) {
$metalDefaultEx = explode('x', $result[0]['default_metal']);
}
?>
<div class="panel-group customize_breakup" id="custmizepro">
<div class="panel">
<div class="panel-heading" role="tab" id="custmizeprod">
<h4 class="panel-title">
<a role="button" class="collapsed" data-toggle="collapse" data-parent="#custmizepro" href="#custmizeproid" aria-expanded="false" aria-controls="collapseTwo">Customize This Product</a>
</h4>
</div>
<div id="custmizeproid" class="collapse" role="tabpanel" aria-labelledby="custmizeprod">
<div class="panel-body">
<div class="row">
<div class="col-md-6 metalformation1">
<label class="metal_label">Metal Selection : </label>
<select name="metal" id="metal" class="attr metal_type_cls">
<option value="">Select Metal</option>
<?php foreach ($metalOptionIds as $valMetal): ?>
<option value="<?php echo $valMetal; ?>" <?php
if ($metalDefaultEx[0] == $valMetal) {
echo "selected";
}
?>><?php echo $metalOptionLabels[$valMetal]; ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 metalformation2">
<div>
<?php
$i = 0;
foreach ($purityOptionIds as $valPurity):
?>
<label class="radio-inline" for="purity_<?php echo $purityOptionIds[$i]; ?>"><?php echo $purityOptionLabels[$valPurity]; ?></label>
<input class="attr" type="radio" value="<?php echo $purityOptionIds[$i]; ?>" id="purity_<?php echo $purityOptionIds[$i]; ?>" name="purity" <?php if ($metalDefaultEx[1] == $valPurity) { ?> checked="checked" <?php } ?>>
<?php
$i++;
endforeach;
?>
</div>
</div>
</div>
<?php
if ($attribute_set_name != 'Necklace' && $attribute_set_name != 'Bangel Size'):
$ccAddedIds = array();
$ccAddedIds = $block->getDiamondColourClarity();
$ccOptLabelSelected = $block->getDiamondClarityOptions();
?>
<div class="metalformation3">
<label class="diamond_selection">Diamond Quality : </label>
<div class="diamond_quality">
<?php
foreach ($ccAddedIds as $valCC):
$sqlDiamondColor = "SELECT * FROM sm_diamond_color_size_data WHERE product_id='" . $productId . "' AND color_clarity_id ='" . $valCC . "' ";
$resultDiamondColor = $connection->fetchAll($sqlDiamondColor);
//$cnt = count($resultDiamondColor);
?>
<input class="attr" type="radio" value="<?php echo $valCC; ?>" id="diamond_<?php echo $valCC; ?>" name="diamond"
<?php
if (!empty($resultDiamondColor)) {
if ($resultDiamondColor[0]['color_clarity_id'] == $valCC) {
?>checked="checked" <?php
}
}
?>>
<label class="radio-inline" for="diamond_<?php echo $valCC; ?>"><?php echo $ccOptLabelSelected[$valCC]; ?></label>
<?php
endforeach;
?>
</div>
</div>
<?php
endif;
?>
</div>
</div>
</div>
</div><!-- panel-group -->
</div><!-- container -->
<div class="metalformation4 row">
<?php
if ($attribute_set_name != 'Pendants' && $attribute_set_name != 'Earring' && $attribute_set_name != 'Necklace' && $attribute_set_name != 'Mangalsutra' && $attribute_set_name != 'Nose Pin' && $attribute_set_name != 'Pendant') {
if($attribute_set_name =='Bangel Size'){
$attributeCode ='bangel_size';
}else{
$attributeCode ='ring_size';
}
$entityType = 'catalog_product';
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$attributeInfo = $objectManager->create(\Magento\Eav\Model\Entity\Attribute::class)->loadByCode($entityType, $attributeCode);
$attributeId = $attributeInfo->getAttributeId();
if($attribute_set_name =='Bangel Size'){
$ringSizeIds = explode(',', $currentProduct->getBangelSize());
} else {
$ringSizeIds = explode(',', $currentProduct->getRingSize());
}
//$ds = array();
$RingSizecnt = count($ringSizeIds);
$attributeRigSize = $objectManager->create(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection::class)
->setPositionOrder('asc')
->setAttributeFilter($attributeId)
->setStoreFilter()
->load();
if (!empty($attributeRigSize->getData()))
foreach ($attributeRigSize as $ringSize) {
if (in_array($ringSize->getOptionId(), $ringSizeIds)) {
$rSize[] = [
'value' => $ringSize->getOptionId(),
'label' => $ringSize->getValue()
];
}
}
?>
<div class="col-md-6">
<?php if($attribute_set_name =='Bangel Size'){ ?>
<label class="diamond_selectiond">Bangel Size : </label>
<?php } else { ?>
<label class="diamond_selectiond">Ring Size : </label>
<?php } ?>
<div>
<?php
$sqlColorSize = "SELECT * FROM sm_diamond_color_size_data WHERE product_id ='" . $currentProduct->getId() . "'";
$sizeDataCollection = $connection->fetchAll($sqlColorSize);
?>
<select id="itemSize" name="itemSize" class="attr">
<option value="">Select Size</option>
<?php foreach ($rSize as $ringSizeData): ?>
<option value="<?php echo $ringSizeData['value']; ?>" <?php
if ($sizeDataCollection[0]['ring_size'] == $ringSizeData['value']) {
echo "selected";
}
?>><?php echo $ringSizeData['label']; ?></option>
<?php endforeach;
?>
</select>
</div>
<div class="ring_size_guide_div">
<?php if($attribute_set_name =='Bangel Size'){ ?>
<a href="<?php echo $block->getUrl("pub/media/wysiwyg/alothemes/static/")?>BANGLE_SIZE_ GUIDE_V1.pdf" class="ring_size_guide" target="_blank">Find your bangle size here</a>
<?php } else { ?>
<a href="<?php echo $block->getUrl("pub/media/wysiwyg/alothemes/static/")?>Ring_Measuring_Guide_Kalon.pdf" class="ring_size_guide" target="_blank">Find your ring size here</a>
<?php } ?>
</div>
</div>
<?php
}
?>
<div class="col-md-6 shipping_date_div">
<div class="Delivery_date">
<div><img class="img-responsive" src="<?php echo $block->getUrl("pub/media/wysiwyg/alothemes/static/")?>shipping_date.png">
<p>Delivery By </p></div>
<div class="shipping_date_value"><p>Sept 29</p></div>
</div>
<div class="shipping_guide_div">
<p>This is a tentative delivery date*</p>
</div>
</div>
</div>
<input type="hidden" class="attr" name="fancyStonePrice" value="<?php echo $fancyStonePrice; ?>">
<!--<input class="attr" type="hidden" value="1" name="priceFirstCheck" id="priceFirstCheck">-->
<script>
require(['jquery'], function ($) {
$(document).on("change", ".attr", function () {
var metal_id = $(this).attr('id');
calculatePrice(0);
if (metal_id == 'metal') {
var url1 = '<?php echo $block->getUrl('calculateprice/index/images') ?>';
var text = $("#metal option:selected").text();
text = text.toLowerCase();
var productId = '<?php echo $productId ?>';
$.ajax({
type: "POST",
url: url1,
showLoader: true,
dataType: "JSON",
data: {'metal': text, 'product': productId},
success: function (data) {
var thumbImage = data[0].thumb;
$(".fotorama__stage__frame img").attr("src",thumbImage);
$(".fotorama__stage__frame img").attr("href",thumbImage);
}
});
}
});
function calculatePrice(isLoad) {
var productId = '<?php echo $productId ?>';
$(".loader").show();
var str = "";
var str = "productId=" + productId + "&isLoad=" + isLoad;
var namelist = new Array();
$(".attr").each(function (i) {
var n = $(this).attr("name");
if (namelist.indexOf(n) == -1) {
if (str != "") {
str += "&";
}
if ($(this).attr("type") == "radio") {
str += $(this).attr("name") + "=" + $("input[name=" + $(this).attr("name") + "]:checked").val();
} else {
str += $(this).attr("name") + "=" + $(this).val();
}
namelist.push($(this).attr("name"));
}
});
var url = '<?php echo $block->getUrl('calculateprice/index/index') ?>' + "?" + str;
var currencySymbol = '<?php echo $currencySymbol; ?>';
// console.log(url);
//var url = calculatepriceUrl+"?"+str;
$.ajax({
type: "POST",
url: url,
showLoader: true,
dataType: "JSON",
success: function (data) {
//+ Math.round(data.cashpolish) + Math.round(data.setRateCost) + Math.round(data.supplimentaryPrice) + Math.round(data.profitMargin)
//var productPrice = (Math.round(data.metalTotalPrice) + Math.round(data.diamondTotalPrice) + Math.round(data.fancyStonePrice) + Math.round(data.vatTotal)); //+ Math.round(data.makingChargeTotal)
var productPrice = (data.finalProductTotal);
//var productPrice = (Math.round(data.metalTotalPrice)) + (Math.round(data.diamondTotalPrice)) + (Math.round(data.makingChargeTotal)) + (data.vatTotal)
$('.price').html(currencySymbol + productPrice);
if (data.fancyStonePrice > 0) {
$('#stoneTotalPrice').html(currencySymbol +(data.fancyStonePrice));
}
$('#metalTotalPrice').html(currencySymbol + (data.metalTotalPrice));
$('#diamondTotalPrice').html(currencySymbol + (data.diamondTotalPrice));
$('#makingChargeTotal').html(currencySymbol + (data.makingChargeTotal));
$('#vatTotal').html(currencySymbol + (data.vatTotal));
$('#metalWeight').html(data.metalWeight);
$('#metalweight1').html(data.metalWeight);
$('#metalType1').html(data.metalType);
$('#metalPurity1').html(data.metalPurity);
$('#grossweight').html(data.grossweight);
$('#metalType').html(data.metalType);
$('#metalPurity').html(data.metalPurity);
$('#diamondclarity').html(data.diamondclarity);
$('#diamondcolor').html(data.diamondcolor);
$('#diamondweight').html(data.diamondweight);
$(".loader").hide();
}
});
}
function ready(callbackFunction) {
if (document.readyState != 'loading')
callbackFunction(event)
else
document.addEventListener("DOMContentLoaded", callbackFunction)
}
ready(event => {
calculatePrice(0);
})
});
</script>
<style type="text/css">
select.metal_type_cls option[value="71"]
{
background-image: url('../pub/media/wysiwyg/alothemes/static/yellow_gold.jpg') !important;
background-position: calc(100% - 20px) calc(100% - 10px);
width: 200px !important;
padding-left: 35px !important;
}
select.metal_type_cls option[value="69"]
{
background-image: url('pub/media/wysiwyg/alothemes/static/yellow_gold.jpg') !important;
background-position: calc(100% - 20px) calc(100% - 10px);
background-repeat: no-repeat;
width: 200px !important;
padding-left: 35px !important;
}
select.metal_type_cls option[value="70"]
{
background-image: url('../pub/media/wysiwyg/alothemes/static/rose_gold.jpg') !important;
background-position: calc(100% - 20px) calc(100% - 10px);
background-repeat: no-repeat;
width: 200px !important;
padding-left: 35px !important;
}
/*select.metal_type_cls {
appearance: none !important;
-moz-appearance: none !important;
-webkit-appearance: none !important;
text-indent: 0.01px !important;
text-overflow: "" !important;
}*/
</style>