Skip to content

Commit

Permalink
- Product Value into Form using Payment Widget
Browse files Browse the repository at this point in the history
  • Loading branch information
alegauss committed Aug 24, 2018
1 parent 88f4731 commit 312f9d9
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 13 deletions.
36 changes: 36 additions & 0 deletions src/main/java/com/viglet/shiohara/ecommerce/ShEcomProductBean.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.viglet.shiohara.ecommerce;

public class ShEcomProductBean {

private String name;

private String description;

private double value;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public double getValue() {
return value;
}

public void setValue(double value) {
this.value = value;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.thymeleaf.context.Context;
import org.thymeleaf.spring5.SpringTemplateEngine;

import com.viglet.shiohara.ecommerce.ShEcomProductBean;
import com.viglet.shiohara.ecommerce.payment.ShPaymentSlip;
import com.viglet.shiohara.persistence.model.ecommerce.ShEcomPaymentTypeDefinition;
import com.viglet.shiohara.persistence.model.post.ShPost;
Expand Down Expand Up @@ -50,17 +51,31 @@ public String render(ShPostTypeAttr shPostTypeAttr) {
String paymentTypeId = paymentType.getString("id");
ShPost shPaymentTypePost = shPostRepository.findById(paymentTypeId).get();
Map<String, ShPostAttr> shPaymentTypePostMap = shPostUtils.postToMap(shPaymentTypePost);

ShPostAttr shPaymentTypeDefinitionPostAttr = shPaymentTypePostMap.get("PAYMENT_TYPE_DEFINITION");
JSONObject ptdJSON = new JSONObject(shPaymentTypeDefinitionPostAttr.getStrValue());


ShEcomPaymentTypeDefinition shEcomPaymentTypeDefinition = shEcomPaymentTypeDefinitionRepository
.findById(ptdJSON.getString("id")).get();
paymentType.put("formPath", shEcomPaymentTypeDefinition.getFormPath());
}

// Product BEGIN
JSONObject product = settings.getJSONObject("product");
ShPost shProductPost = shPostRepository.findById(product.getString("post")).get();
Map<String, ShPostAttr> shProductPostMap = shPostUtils.postToMap(shProductPost);

ShEcomProductBean shProduct = new ShEcomProductBean();
shProduct.setName(shProductPostMap.get(product.getString("name")).getStrValue());
shProduct.setDescription(shProductPostMap.get(product.getString("description")).getStrValue());
shProduct.setValue(Double.valueOf(shProductPostMap.get(product.getString("value")).getStrValue()));

/// Product END

final Context ctx = new Context();
ctx.setVariable("shPostTypeAttr", shPostTypeAttr);
ctx.setVariable("shProduct", shProduct);
ctx.setVariable("paymentTypes", paymentTypes);
return templateEngine.process("widget/payment/payment-widget", ctx);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ shioharaApp
var paymentTypeId = {};
paymentTypeId.id = paymentType.id;
paymentTypeId.name = "PaymentType "
+ (shPostTypeAttr.widgetSettingsObject.paymentTypes.length + 1)
+ (shPostTypeAttr.widgetSettingsObject.paymentTypes.length + 1);
paymentTypeId.identifier = "PAYMENT_TYPE_"
+ (shPostTypeAttr.widgetSettingsObject.paymentTypes.length + 1);
shPostTypeAttr.widgetSettingsObject.paymentTypes
.push(paymentTypeId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
style="padding: 0px; padding-top: 5px">
<b>Order</b>
</div>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-6"

<div class="col-lg-3 col-md-3 col-sm-3 hidden-xs"
style="padding: 0px; padding-top: 5px">
<b>Type</b>
<b>Name</b>
</div>
<div class="col-lg-3 col-md-3 col-sm-3 hidden-xs"
style="padding: 0px; padding-top: 5px">
<b>Name</b>
<b>Identifier</b>
</div>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-6"
style="padding: 0px; padding-top: 5px">
<b>Type</b>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,14 @@
<i class="fa fa-bars" aria-hidden="true"></i>
{{paymentType.ordinal}} <span style="display: none;">{{paymentType.ordinal=$index+1}}</span>
</div>
<div class="col-lg-3 col-md-3 col-sm-3 hidden-xs"
style="padding: 0px">{{paymentType.name}}</div>
<div class="col-lg-3 col-md-3 col-sm-3 hidden-xs"
style="padding: 0px">{{paymentType.identifier}}</div>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-6"
style="padding: 0px">{{
$parent.$parent.getPaymentType(paymentType.id).title }}</div>
<div class="col-lg-3 col-md-3 col-sm-3 hidden-xs"
style="padding: 0px">{{paymentType.name}}</div>


</div>
</uib-accordion-heading>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<label for="parcelas"> Parcelas </label> <select class="form-control"
name="parcelas" id="parcelas">

<option value="01">1x de 25,00</option>
<option value="02">2x de 12,50</option>
<option value="01" th:text="'1x de R$ ' + ${#numbers.formatDecimal(shProduct.value, 0, 'POINT', 2, 'COMMA')}"></option>
<option value="02" th:text="'2x de R$' + ${#numbers.formatDecimal(shProduct.value/2, 0, 'POINT', 2, 'COMMA')}"></option>
</select>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<label for="parcelas"> Parcelas </label> <select class="form-control"
name="parcelas" id="parcelas">

<option value="01">1x de 25,00</option>
<option value="02">2x de 12,50</option>
<option value="01" th:text="'1x de R$ ' + ${#numbers.formatDecimal(shProduct.value, 0, 'POINT', 2, 'COMMA')}"></option>
<option value="02" th:text="'2x de R$' + ${#numbers.formatDecimal(shProduct.value/2, 0, 'POINT', 2, 'COMMA')}"></option>
</select>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<label for="parcelas"> Parcelas </label> <select class="form-control"
name="parcelas" id="parcelas">

<option value="01">1x de 25,00</option>
<option value="02">2x de 12,50</option>
<option value="01" th:text="'1x de R$ ' + ${#numbers.formatDecimal(shProduct.value, 0, 'POINT', 2, 'COMMA')}"></option>
<option value="02" th:text="'2x de R$' + ${#numbers.formatDecimal(shProduct.value/2, 0, 'POINT', 2, 'COMMA')}"></option>
</select>
</div>

0 comments on commit 312f9d9

Please sign in to comment.