Exemple #1
0
  /**
   * Construct page.
   *
   * @param params page parameters
   */
  public ResultPage(final PageParameters params) {

    super(params);

    add(new StandardFooter(FOOTER)).add(new StandardHeader(HEADER));

    final String orderNum = params.get("orderNum").toString();

    final CustomerOrder customerOrder = checkoutServiceFacade.findByGuid(orderNum);

    final boolean isPaymentSuccessful =
        checkoutServiceFacade.isOrderPaymentSuccessful(customerOrder);

    if (isPaymentSuccessful) {
      cleanCart();
    }

    add(
        new Label(
            "paymentResult",
            getLocalizer()
                .getString(isPaymentSuccessful ? "paymentWasOk" : "paymentWasFailed", this)));

    add(new ServerSideJs("serverSideJs"));

    add(new HeaderMetaInclude("headerInclude"));
  }
  /**
   * Construct payment form verification view, that shows deliveries, items in deliveries and
   * prices.
   *
   * @param id component id
   * @param orderGuid order guid
   */
  public ShoppingCartPaymentVerificationView(
      final String id, final String orderGuid, final boolean enableProductLinks) {
    super(id);

    final CustomerOrder customerOrder = checkoutServiceFacade.findByGuid(orderGuid);
    final Total grandTotal = checkoutServiceFacade.getOrderTotal(customerOrder);

    final String selectedLocale = getLocale().getLanguage();
    final Set<String> allPromos = checkoutServiceFacade.getOrderPromoCodes(customerOrder);
    for (final CustomerOrderDelivery delivery : customerOrder.getDelivery()) {
      allPromos.addAll(checkoutServiceFacade.getOrderShippingPromoCodes(delivery));
    }
    for (final CustomerOrderDet orderDet : customerOrder.getOrderDetail()) {
      allPromos.addAll(checkoutServiceFacade.getOrderItemPromoCodes(orderDet));
    }

    final String deliveryAddress = customerOrder.getShippingAddress();
    final String billingAddress = customerOrder.getBillingAddress();

    final Pair<String, String> imageSize =
        categoryServiceFacade.getThumbnailSizeConfig(0L, ShopCodeContext.getShopId());

    add(
        new ListView<CustomerOrderDelivery>(
            DELIVERY_LIST, new ArrayList<CustomerOrderDelivery>(customerOrder.getDelivery())) {

          @Override
          protected void populateItem(
              ListItem<CustomerOrderDelivery> customerOrderDeliveryListItem) {

            final CustomerOrderDelivery delivery = customerOrderDeliveryListItem.getModelObject();
            final CarrierSla sla = delivery.getCarrierSla();

            final String slaName =
                getI18NSupport()
                    .getFailoverModel(sla.getDisplayName(), sla.getName())
                    .getValue(selectedLocale);

            final List<CustomerOrderDeliveryDet> deliveryDet =
                new ArrayList<CustomerOrderDeliveryDet>(delivery.getDetail());

            final Total total =
                checkoutServiceFacade.getOrderDeliveryTotal(customerOrder, delivery);

            customerOrderDeliveryListItem
                .add(new Label(DELIVERY_CODE, delivery.getDeliveryNum()))
                .add(
                    new ListView<CustomerOrderDeliveryDet>(ITEM_LIST, deliveryDet) {

                      @Override
                      protected void populateItem(
                          ListItem<CustomerOrderDeliveryDet> customerOrderDeliveryDetListItem) {

                        final CustomerOrderDeliveryDet det =
                            customerOrderDeliveryDetListItem.getModelObject();

                        final ProductSkuDecorator productSkuDecorator =
                            getDecoratorFacade()
                                .decorate(
                                    productServiceFacade.getProductSkuBySkuCode(
                                        det.getProductSkuCode()),
                                    getWicketUtil().getHttpServletRequest().getContextPath(),
                                    true);

                        final String width = imageSize.getFirst();
                        final String height = imageSize.getSecond();

                        final String lang = getLocale().getLanguage();
                        final String defaultImageRelativePath =
                            productSkuDecorator.getDefaultImage(width, height, lang);

                        final BigDecimal itemTotal =
                            det.getPrice()
                                .multiply(det.getQty())
                                .setScale(Constants.DEFAULT_SCALE, BigDecimal.ROUND_HALF_UP);

                        final LinksSupport links = getWicketSupportFacade().links();

                        customerOrderDeliveryDetListItem
                            .add(
                                links
                                    .newProductSkuLink(ITEM_NAME_LINK, productSkuDecorator.getId())
                                    .add(
                                        new Label(
                                            ITEM_NAME_LINK_NAME,
                                            productSkuDecorator.getName(selectedLocale)))
                                    .setVisible(enableProductLinks))
                            .add(
                                new Label(ITEM_NAME, productSkuDecorator.getName(selectedLocale))
                                    .setVisible(!enableProductLinks))
                            .add(new Label(ITEM_CODE, det.getProductSkuCode()))
                            .add(new Label(ITEM_PRICE, det.getPrice().toString()))
                            .add(new Label(ITEM_QTY, det.getQty().toString()))
                            .add(new Label(ITEM_TOTAL, itemTotal.toString()))
                            .add(
                                new ContextImage(DEFAULT_IMAGE, defaultImageRelativePath)
                                    .add(
                                        new AttributeModifier(BaseComponent.HTML_WIDTH, width),
                                        new AttributeModifier(BaseComponent.HTML_HEIGHT, height)));
                      }
                    })
                .add(new Label(DELIVERY_SUB_TOTAL, total.getSubTotal().toString()))
                .add(new Label(DELIVERY_SUB_TOTAL_TAX, total.getSubTotalTax().toString()))
                .add(new Label(DELIVERY_SUB_TOTAL_AMOUNT, total.getSubTotalAmount().toString()))
                .add(new Label(DELIVERY_COST, total.getDeliveryCost().toString()))
                .add(new Label(DELIVERY_COST_TAX, total.getDeliveryTax().toString()))
                .add(new Label(DELIVERY_COST_AMOUNT, total.getDeliveryCostAmount().toString()))
                .add(new Label(DELIVERY_METHOD, slaName))
                .add(new Label(DELIVERY_ADDRESS, deliveryAddress));
          }
        });

    add(new Label(DELIVERY_GRAND_TOTAL, grandTotal.getTotal().toString()));
    add(new Label(BILLING_ADDRESS, billingAddress));
    add(new Label(DELIVERY_GRAND_TAX, grandTotal.getTotalTax().toString()));
    add(
        new PriceView(
            DELIVERY_GRAND_AMOUNT,
            new Pair<BigDecimal, BigDecimal>(
                grandTotal.getListTotalAmount(), grandTotal.getTotalAmount()),
            customerOrder.getCurrency(),
            StringUtils.join(allPromos, ", "),
            true,
            true));
  }