001
014
015 package com.liferay.portlet.shopping.service.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.util.GetterUtil;
020 import com.liferay.portal.kernel.util.Validator;
021 import com.liferay.portal.kernel.workflow.WorkflowConstants;
022 import com.liferay.portal.model.User;
023 import com.liferay.portal.service.ServiceContext;
024 import com.liferay.portal.util.PortletKeys;
025 import com.liferay.portal.util.PropsValues;
026 import com.liferay.portal.util.SubscriptionSender;
027 import com.liferay.portlet.shopping.BillingCityException;
028 import com.liferay.portlet.shopping.BillingCountryException;
029 import com.liferay.portlet.shopping.BillingEmailAddressException;
030 import com.liferay.portlet.shopping.BillingFirstNameException;
031 import com.liferay.portlet.shopping.BillingLastNameException;
032 import com.liferay.portlet.shopping.BillingPhoneException;
033 import com.liferay.portlet.shopping.BillingStateException;
034 import com.liferay.portlet.shopping.BillingStreetException;
035 import com.liferay.portlet.shopping.BillingZipException;
036 import com.liferay.portlet.shopping.CCExpirationException;
037 import com.liferay.portlet.shopping.CCNameException;
038 import com.liferay.portlet.shopping.CCNumberException;
039 import com.liferay.portlet.shopping.CCTypeException;
040 import com.liferay.portlet.shopping.CartMinOrderException;
041 import com.liferay.portlet.shopping.ShippingCityException;
042 import com.liferay.portlet.shopping.ShippingCountryException;
043 import com.liferay.portlet.shopping.ShippingEmailAddressException;
044 import com.liferay.portlet.shopping.ShippingFirstNameException;
045 import com.liferay.portlet.shopping.ShippingLastNameException;
046 import com.liferay.portlet.shopping.ShippingPhoneException;
047 import com.liferay.portlet.shopping.ShippingStateException;
048 import com.liferay.portlet.shopping.ShippingStreetException;
049 import com.liferay.portlet.shopping.ShippingZipException;
050 import com.liferay.portlet.shopping.model.ShoppingCart;
051 import com.liferay.portlet.shopping.model.ShoppingCartItem;
052 import com.liferay.portlet.shopping.model.ShoppingItem;
053 import com.liferay.portlet.shopping.model.ShoppingItemField;
054 import com.liferay.portlet.shopping.model.ShoppingOrder;
055 import com.liferay.portlet.shopping.model.ShoppingOrderConstants;
056 import com.liferay.portlet.shopping.model.ShoppingOrderItem;
057 import com.liferay.portlet.shopping.model.impl.ShoppingCartItemImpl;
058 import com.liferay.portlet.shopping.service.base.ShoppingOrderLocalServiceBaseImpl;
059 import com.liferay.portlet.shopping.util.ShoppingPreferences;
060 import com.liferay.portlet.shopping.util.ShoppingUtil;
061 import com.liferay.portlet.shopping.util.comparator.OrderDateComparator;
062 import com.liferay.util.CreditCard;
063 import com.liferay.util.PwdGenerator;
064
065 import java.util.Currency;
066 import java.util.Date;
067 import java.util.List;
068 import java.util.Map;
069
070
073 public class ShoppingOrderLocalServiceImpl
074 extends ShoppingOrderLocalServiceBaseImpl {
075
076 @Override
077 public ShoppingOrder addLatestOrder(long userId, long groupId)
078 throws PortalException, SystemException {
079
080
081
082 User user = userPersistence.findByPrimaryKey(userId);
083 Date now = new Date();
084
085 String number = getNumber();
086
087 ShoppingOrder order = null;
088
089 long orderId = counterLocalService.increment();
090
091 List<ShoppingOrder> pastOrders =
092 shoppingOrderPersistence.findByG_U_PPPS(
093 groupId, userId, ShoppingOrderConstants.STATUS_CHECKOUT, 0, 1);
094
095 if (pastOrders.size() > 0) {
096 ShoppingOrder pastOrder = pastOrders.get(0);
097
098 order = shoppingOrderPersistence.create(orderId);
099
100 order.setBillingCompany(pastOrder.getBillingCompany());
101 order.setBillingStreet(pastOrder.getBillingStreet());
102 order.setBillingCity(pastOrder.getBillingCity());
103 order.setBillingState(pastOrder.getBillingState());
104 order.setBillingZip(pastOrder.getBillingZip());
105 order.setBillingCountry(pastOrder.getBillingCountry());
106 order.setBillingPhone(pastOrder.getBillingPhone());
107 order.setShipToBilling(pastOrder.isShipToBilling());
108 order.setShippingCompany(pastOrder.getShippingCompany());
109 order.setShippingStreet(pastOrder.getShippingStreet());
110 order.setShippingCity(pastOrder.getShippingCity());
111 order.setShippingState(pastOrder.getShippingState());
112 order.setShippingZip(pastOrder.getShippingZip());
113 order.setShippingCountry(pastOrder.getShippingCountry());
114 order.setShippingPhone(pastOrder.getShippingPhone());
115 }
116 else {
117 order = shoppingOrderPersistence.create(orderId);
118 }
119
120 order.setGroupId(groupId);
121 order.setCompanyId(user.getCompanyId());
122 order.setUserId(user.getUserId());
123 order.setUserName(user.getFullName());
124 order.setCreateDate(now);
125 order.setModifiedDate(now);
126 order.setNumber(number);
127 order.setBillingFirstName(user.getFirstName());
128 order.setBillingLastName(user.getLastName());
129 order.setBillingEmailAddress(user.getEmailAddress());
130 order.setShippingFirstName(user.getFirstName());
131 order.setShippingLastName(user.getLastName());
132 order.setShippingEmailAddress(user.getEmailAddress());
133 order.setCcName(user.getFullName());
134 order.setPpPaymentStatus(ShoppingOrderConstants.STATUS_LATEST);
135 order.setSendOrderEmail(true);
136 order.setSendShippingEmail(true);
137
138 shoppingOrderPersistence.update(order);
139
140
141
142 if (PropsValues.SHOPPING_ORDER_COMMENTS_ENABLED) {
143 mbMessageLocalService.addDiscussionMessage(
144 userId, order.getUserName(), groupId,
145 ShoppingOrder.class.getName(), orderId,
146 WorkflowConstants.ACTION_PUBLISH);
147 }
148
149 return order;
150 }
151
152 @Override
153 public void completeOrder(
154 String number, String ppTxnId, String ppPaymentStatus,
155 double ppPaymentGross, String ppReceiverEmail, String ppPayerEmail,
156 boolean updateInventory, ServiceContext serviceContext)
157 throws PortalException, SystemException {
158
159
160
161 ShoppingOrder order = shoppingOrderPersistence.findByNumber(number);
162
163 order.setModifiedDate(new Date());
164 order.setPpTxnId(ppTxnId);
165 order.setPpPaymentStatus(ppPaymentStatus);
166 order.setPpPaymentGross(ppPaymentGross);
167 order.setPpReceiverEmail(ppReceiverEmail);
168 order.setPpPayerEmail(ppPayerEmail);
169
170 shoppingOrderPersistence.update(order);
171
172
173
174 if (updateInventory &&
175 ppPaymentStatus.equals(ShoppingOrderConstants.STATUS_COMPLETED)) {
176
177 List<ShoppingOrderItem> orderItems =
178 shoppingOrderItemLocalService.getOrderItems(order.getOrderId());
179
180 for (ShoppingOrderItem orderItem : orderItems) {
181 ShoppingItem item = shoppingItemLocalService.getItem(
182 ShoppingUtil.getItemId(orderItem.getItemId()));
183
184 if (!item.isFields()) {
185 int quantity =
186 item.getStockQuantity() - orderItem.getQuantity();
187
188 item.setStockQuantity(quantity);
189 }
190 else {
191 List<ShoppingItemField> itemFields =
192 shoppingItemFieldLocalService.getItemFields(
193 item.getItemId());
194
195 ShoppingItemField[] itemFieldsArray = itemFields.toArray(
196 new ShoppingItemField[itemFields.size()]);
197
198 String[] fieldsArray = ShoppingCartItemImpl.getFieldsArray(
199 ShoppingUtil.getItemFields(orderItem.getItemId()));
200
201 int rowPos = ShoppingUtil.getFieldsQuantitiesPos(
202 item, itemFieldsArray, fieldsArray);
203
204 String[] fieldsQuantities = item.getFieldsQuantitiesArray();
205
206 try {
207 int quantity =
208 GetterUtil.getInteger(fieldsQuantities[rowPos]) -
209 orderItem.getQuantity();
210
211 fieldsQuantities[rowPos] = String.valueOf(quantity);
212
213 item.setFieldsQuantitiesArray(fieldsQuantities);
214 }
215 catch (Exception e) {
216 }
217 }
218
219 shoppingItemPersistence.update(item);
220 }
221 }
222
223
224
225 sendEmail(order, "confirmation", serviceContext);
226 }
227
228 @Override
229 public void deleteOrder(long orderId)
230 throws PortalException, SystemException {
231
232 ShoppingOrder order = shoppingOrderPersistence.findByPrimaryKey(
233 orderId);
234
235 deleteOrder(order);
236 }
237
238 @Override
239 public void deleteOrder(ShoppingOrder order)
240 throws PortalException, SystemException {
241
242
243
244 shoppingOrderPersistence.remove(order);
245
246
247
248 subscriptionLocalService.deleteSubscriptions(
249 order.getCompanyId(), ShoppingOrder.class.getName(),
250 order.getOrderId());
251
252
253
254 shoppingOrderItemPersistence.removeByOrderId(order.getOrderId());
255
256
257
258 mbMessageLocalService.deleteDiscussionMessages(
259 ShoppingOrder.class.getName(), order.getOrderId());
260 }
261
262 @Override
263 public void deleteOrders(long groupId)
264 throws PortalException, SystemException {
265
266 List<ShoppingOrder> orders = shoppingOrderPersistence.findByGroupId(
267 groupId);
268
269 for (ShoppingOrder order : orders) {
270 deleteOrder(order);
271 }
272 }
273
274 @Override
275 public ShoppingOrder getLatestOrder(long userId, long groupId)
276 throws PortalException, SystemException {
277
278 List<ShoppingOrder> orders = shoppingOrderPersistence.findByG_U_PPPS(
279 groupId, userId, ShoppingOrderConstants.STATUS_LATEST, 0, 1);
280
281 ShoppingOrder order = null;
282
283 if (orders.size() == 1) {
284 order = orders.get(0);
285 }
286 else {
287 order = shoppingOrderLocalService.addLatestOrder(userId, groupId);
288 }
289
290 return order;
291 }
292
293 @Override
294 public ShoppingOrder getOrder(long orderId)
295 throws PortalException, SystemException {
296
297 return shoppingOrderPersistence.findByPrimaryKey(orderId);
298 }
299
300 @Override
301 public ShoppingOrder getOrder(String number)
302 throws PortalException, SystemException {
303
304 return shoppingOrderPersistence.findByNumber(number);
305 }
306
307 @Override
308 public ShoppingOrder getPayPalTxnIdOrder(String ppTxnId)
309 throws PortalException, SystemException {
310
311 return shoppingOrderPersistence.findByPPTxnId(ppTxnId);
312 }
313
314 @Override
315 public ShoppingOrder saveLatestOrder(ShoppingCart cart)
316 throws PortalException, SystemException {
317
318 Map<ShoppingCartItem, Integer> items = cart.getItems();
319 Date now = new Date();
320
321 ShoppingPreferences shoppingPrefs = ShoppingPreferences.getInstance(
322 cart.getCompanyId(), cart.getGroupId());
323
324 if (!ShoppingUtil.meetsMinOrder(shoppingPrefs, items)) {
325 throw new CartMinOrderException();
326 }
327
328 ShoppingOrder order = getLatestOrder(
329 cart.getUserId(), cart.getGroupId());
330
331 order.setCreateDate(now);
332 order.setModifiedDate(now);
333 order.setPpPaymentStatus(ShoppingOrderConstants.STATUS_CHECKOUT);
334
335 shoppingOrderPersistence.update(order);
336
337 boolean requiresShipping = false;
338
339 for (Map.Entry<ShoppingCartItem, Integer> entry : items.entrySet()) {
340 ShoppingCartItem cartItem = entry.getKey();
341 Integer count = entry.getValue();
342
343 ShoppingItem item = cartItem.getItem();
344
345 if (item.isRequiresShipping()) {
346 requiresShipping = true;
347 }
348
349 long orderItemId = counterLocalService.increment();
350
351 ShoppingOrderItem orderItem = shoppingOrderItemPersistence.create(
352 orderItemId);
353
354 orderItem.setOrderId(order.getOrderId());
355 orderItem.setItemId(cartItem.getCartItemId());
356 orderItem.setSku(item.getSku());
357 orderItem.setName(item.getName());
358 orderItem.setDescription(item.getDescription());
359 orderItem.setProperties(item.getProperties());
360 orderItem.setPrice(
361 ShoppingUtil.calculateActualPrice(item, count.intValue()) /
362 count.intValue());
363 orderItem.setQuantity(count.intValue());
364
365 shoppingOrderItemPersistence.update(orderItem);
366 }
367
368 order.setModifiedDate(new Date());
369 order.setTax(ShoppingUtil.calculateTax(items, order.getBillingState()));
370 order.setShipping(
371 ShoppingUtil.calculateAlternativeShipping(
372 items, cart.getAltShipping()));
373 order.setAltShipping(
374 shoppingPrefs.getAlternativeShippingName(cart.getAltShipping()));
375 order.setRequiresShipping(requiresShipping);
376 order.setInsure(cart.isInsure());
377 order.setInsurance(ShoppingUtil.calculateInsurance(items));
378 order.setCouponCodes(cart.getCouponCodes());
379 order.setCouponDiscount(
380 ShoppingUtil.calculateCouponDiscount(
381 items, order.getBillingState(), cart.getCoupon()));
382 order.setSendOrderEmail(true);
383 order.setSendShippingEmail(true);
384
385 shoppingOrderPersistence.update(order);
386
387 return order;
388 }
389
390 @Override
391 public List<ShoppingOrder> search(
392 long groupId, long companyId, long userId, String number,
393 String billingFirstName, String billingLastName,
394 String billingEmailAddress, String shippingFirstName,
395 String shippingLastName, String shippingEmailAddress,
396 String ppPaymentStatus, boolean andOperator, int start, int end)
397 throws SystemException {
398
399 OrderDateComparator obc = new OrderDateComparator(false);
400
401 return shoppingOrderFinder.findByG_C_U_N_PPPS(
402 groupId, companyId, userId, number, billingFirstName,
403 billingLastName, billingEmailAddress, shippingFirstName,
404 shippingLastName, shippingEmailAddress, ppPaymentStatus,
405 andOperator, start, end, obc);
406 }
407
408 @Override
409 public int searchCount(
410 long groupId, long companyId, long userId, String number,
411 String billingFirstName, String billingLastName,
412 String billingEmailAddress, String shippingFirstName,
413 String shippingLastName, String shippingEmailAddress,
414 String ppPaymentStatus, boolean andOperator)
415 throws SystemException {
416
417 return shoppingOrderFinder.countByG_C_U_N_PPPS(
418 groupId, companyId, userId, number, billingFirstName,
419 billingLastName, billingEmailAddress, shippingFirstName,
420 shippingLastName, shippingEmailAddress, ppPaymentStatus,
421 andOperator);
422 }
423
424 @Override
425 public void sendEmail(
426 long orderId, String emailType, ServiceContext serviceContext)
427 throws PortalException, SystemException {
428
429 ShoppingOrder order = shoppingOrderPersistence.findByPrimaryKey(
430 orderId);
431
432 sendEmail(order, emailType, serviceContext);
433 }
434
435 @Override
436 public void sendEmail(
437 ShoppingOrder order, String emailType,
438 ServiceContext serviceContext)
439 throws PortalException, SystemException {
440
441 ShoppingPreferences shoppingPrefs = ShoppingPreferences.getInstance(
442 order.getCompanyId(), order.getGroupId());
443
444 if (emailType.equals("confirmation") &&
445 shoppingPrefs.getEmailOrderConfirmationEnabled()) {
446 }
447 else if (emailType.equals("shipping") &&
448 shoppingPrefs.getEmailOrderShippingEnabled()) {
449 }
450 else {
451 return;
452 }
453
454 User user = userPersistence.findByPrimaryKey(order.getUserId());
455
456 Currency currency = Currency.getInstance(shoppingPrefs.getCurrencyId());
457
458 String billingAddress =
459 order.getBillingFirstName() + " " + order.getBillingLastName() +
460 "<br>" +
461 order.getBillingEmailAddress() + "<br>" +
462 order.getBillingStreet() + "<br>" +
463 order.getBillingCity() + "<br>" +
464 order.getBillingState() + "<br>" +
465 order.getBillingZip() + "<br>" +
466 order.getBillingCountry() + "<br>" +
467 order.getBillingPhone() + "<br>";
468
469 String shippingAddress =
470 order.getShippingFirstName() + " " + order.getShippingLastName() +
471 "<br>" +
472 order.getShippingEmailAddress() + "<br>" +
473 order.getShippingStreet() + "<br>" +
474 order.getShippingCity() + "<br>" +
475 order.getShippingState() + "<br>" +
476 order.getShippingZip() + "<br>" +
477 order.getShippingCountry() + "<br>" +
478 order.getShippingPhone() + "<br>";
479
480 double total = ShoppingUtil.calculateTotal(order);
481
482 String fromName = shoppingPrefs.getEmailFromName(order.getCompanyId());
483 String fromAddress = shoppingPrefs.getEmailFromAddress(
484 order.getCompanyId());
485
486 String toName = user.getFullName();
487 String toAddress = user.getEmailAddress();
488
489 String subject = null;
490 String body = null;
491
492 if (emailType.equals("confirmation")) {
493 subject = shoppingPrefs.getEmailOrderConfirmationSubject();
494 body = shoppingPrefs.getEmailOrderConfirmationBody();
495 }
496 else if (emailType.equals("shipping")) {
497 subject = shoppingPrefs.getEmailOrderShippingSubject();
498 body = shoppingPrefs.getEmailOrderShippingBody();
499 }
500
501 SubscriptionSender subscriptionSender = new SubscriptionSender();
502
503 subscriptionSender.setBody(body);
504 subscriptionSender.setCompanyId(order.getCompanyId());
505 subscriptionSender.setContextAttributes(
506 "[$ORDER_BILLING_ADDRESS$]", billingAddress, "[$ORDER_CURRENCY$]",
507 currency.getSymbol(), "[$ORDER_NUMBER$]", order.getNumber(),
508 "[$ORDER_SHIPPING_ADDRESS$]", shippingAddress, "[$ORDER_TOTAL$]",
509 total);
510 subscriptionSender.setFrom(fromAddress, fromName);
511 subscriptionSender.setHtmlFormat(true);
512 subscriptionSender.setMailId("shopping_order", order.getOrderId());
513 subscriptionSender.setPortletId(PortletKeys.SHOPPING);
514 subscriptionSender.setScopeGroupId(order.getGroupId());
515 subscriptionSender.setServiceContext(serviceContext);
516 subscriptionSender.setSubject(subject);
517 subscriptionSender.setUserId(order.getUserId());
518
519 subscriptionSender.addRuntimeSubscribers(toAddress, toName);
520
521 subscriptionSender.flushNotificationsAsync();
522
523 if (emailType.equals("confirmation") && order.isSendOrderEmail()) {
524 order.setSendOrderEmail(false);
525
526 shoppingOrderPersistence.update(order);
527 }
528 else if (emailType.equals("shipping") && order.isSendShippingEmail()) {
529 order.setSendShippingEmail(false);
530
531 shoppingOrderPersistence.update(order);
532 }
533 }
534
535 @Override
536 public ShoppingOrder updateLatestOrder(
537 long userId, long groupId, String billingFirstName,
538 String billingLastName, String billingEmailAddress,
539 String billingCompany, String billingStreet, String billingCity,
540 String billingState, String billingZip, String billingCountry,
541 String billingPhone, boolean shipToBilling,
542 String shippingFirstName, String shippingLastName,
543 String shippingEmailAddress, String shippingCompany,
544 String shippingStreet, String shippingCity, String shippingState,
545 String shippingZip, String shippingCountry, String shippingPhone,
546 String ccName, String ccType, String ccNumber, int ccExpMonth,
547 int ccExpYear, String ccVerNumber, String comments)
548 throws PortalException, SystemException {
549
550 ShoppingOrder order = getLatestOrder(userId, groupId);
551
552 return updateOrder(
553 order.getOrderId(), billingFirstName, billingLastName,
554 billingEmailAddress, billingCompany, billingStreet, billingCity,
555 billingState, billingZip, billingCountry, billingPhone,
556 shipToBilling, shippingFirstName, shippingLastName,
557 shippingEmailAddress, shippingCompany, shippingStreet, shippingCity,
558 shippingState, shippingZip, shippingCountry, shippingPhone, ccName,
559 ccType, ccNumber, ccExpMonth, ccExpYear, ccVerNumber, comments);
560 }
561
562 @Override
563 public ShoppingOrder updateOrder(
564 long orderId, String ppTxnId, String ppPaymentStatus,
565 double ppPaymentGross, String ppReceiverEmail, String ppPayerEmail)
566 throws PortalException, SystemException {
567
568 ShoppingOrder order = shoppingOrderPersistence.findByPrimaryKey(
569 orderId);
570
571 order.setModifiedDate(new Date());
572 order.setPpTxnId(ppTxnId);
573 order.setPpPaymentStatus(ppPaymentStatus);
574 order.setPpPaymentGross(ppPaymentGross);
575 order.setPpReceiverEmail(ppReceiverEmail);
576 order.setPpPayerEmail(ppPayerEmail);
577
578 shoppingOrderPersistence.update(order);
579
580 return order;
581 }
582
583 @Override
584 public ShoppingOrder updateOrder(
585 long orderId, String billingFirstName, String billingLastName,
586 String billingEmailAddress, String billingCompany,
587 String billingStreet, String billingCity, String billingState,
588 String billingZip, String billingCountry, String billingPhone,
589 boolean shipToBilling, String shippingFirstName,
590 String shippingLastName, String shippingEmailAddress,
591 String shippingCompany, String shippingStreet, String shippingCity,
592 String shippingState, String shippingZip, String shippingCountry,
593 String shippingPhone, String ccName, String ccType, String ccNumber,
594 int ccExpMonth, int ccExpYear, String ccVerNumber, String comments)
595 throws PortalException, SystemException {
596
597 ShoppingOrder order = shoppingOrderPersistence.findByPrimaryKey(
598 orderId);
599
600 ShoppingPreferences shoppingPrefs = ShoppingPreferences.getInstance(
601 order.getCompanyId(), order.getGroupId());
602
603 validate(
604 shoppingPrefs, billingFirstName, billingLastName,
605 billingEmailAddress, billingStreet, billingCity, billingState,
606 billingZip, billingCountry, billingPhone, shipToBilling,
607 shippingFirstName, shippingLastName, shippingEmailAddress,
608 shippingStreet, shippingCity, shippingState, shippingZip,
609 shippingCountry, shippingPhone, ccName, ccType, ccNumber,
610 ccExpMonth, ccExpYear, ccVerNumber);
611
612 order.setModifiedDate(new Date());
613 order.setBillingFirstName(billingFirstName);
614 order.setBillingLastName(billingLastName);
615 order.setBillingEmailAddress(billingEmailAddress);
616 order.setBillingCompany(billingCompany);
617 order.setBillingStreet(billingStreet);
618 order.setBillingCity(billingCity);
619 order.setBillingState(billingState);
620 order.setBillingZip(billingZip);
621 order.setBillingCountry(billingCountry);
622 order.setBillingPhone(billingPhone);
623 order.setShipToBilling(shipToBilling);
624
625 if (shipToBilling) {
626 order.setShippingFirstName(billingFirstName);
627 order.setShippingLastName(billingLastName);
628 order.setShippingEmailAddress(billingEmailAddress);
629 order.setShippingCompany(billingCompany);
630 order.setShippingStreet(billingStreet);
631 order.setShippingCity(billingCity);
632 order.setShippingState(billingState);
633 order.setShippingZip(billingZip);
634 order.setShippingCountry(billingCountry);
635 order.setShippingPhone(billingPhone);
636 }
637 else {
638 order.setShippingFirstName(shippingFirstName);
639 order.setShippingLastName(shippingLastName);
640 order.setShippingEmailAddress(shippingEmailAddress);
641 order.setShippingCompany(shippingCompany);
642 order.setShippingStreet(shippingStreet);
643 order.setShippingCity(shippingCity);
644 order.setShippingState(shippingState);
645 order.setShippingZip(shippingZip);
646 order.setShippingCountry(shippingCountry);
647 order.setShippingPhone(shippingPhone);
648 }
649
650 order.setCcName(ccName);
651 order.setCcType(ccType);
652 order.setCcNumber(ccNumber);
653 order.setCcExpMonth(ccExpMonth);
654 order.setCcExpYear(ccExpYear);
655 order.setCcVerNumber(ccVerNumber);
656 order.setComments(comments);
657
658 shoppingOrderPersistence.update(order);
659
660 return order;
661 }
662
663 protected String getNumber() throws SystemException {
664 String number = PwdGenerator.getPassword(
665 PwdGenerator.KEY1 + PwdGenerator.KEY2, 12);
666
667 ShoppingOrder order = shoppingOrderPersistence.fetchByNumber(number);
668
669 if (order != null) {
670 return order.getNumber();
671 }
672
673 return number;
674 }
675
676 protected void validate(
677 ShoppingPreferences shoppingPrefs, String billingFirstName,
678 String billingLastName, String billingEmailAddress,
679 String billingStreet, String billingCity, String billingState,
680 String billingZip, String billingCountry, String billingPhone,
681 boolean shipToBilling, String shippingFirstName,
682 String shippingLastName, String shippingEmailAddress,
683 String shippingStreet, String shippingCity, String shippingState,
684 String shippingZip, String shippingCountry, String shippingPhone,
685 String ccName, String ccType, String ccNumber, int ccExpMonth,
686 int ccExpYear, String ccVerNumber)
687 throws PortalException {
688
689 if (Validator.isNull(billingFirstName)) {
690 throw new BillingFirstNameException();
691 }
692 else if (Validator.isNull(billingLastName)) {
693 throw new BillingLastNameException();
694 }
695 else if (!Validator.isEmailAddress(billingEmailAddress)) {
696 throw new BillingEmailAddressException();
697 }
698 else if (Validator.isNull(billingStreet)) {
699 throw new BillingStreetException();
700 }
701 else if (Validator.isNull(billingCity)) {
702 throw new BillingCityException();
703 }
704 else if (Validator.isNull(billingState)) {
705 throw new BillingStateException();
706 }
707 else if (Validator.isNull(billingZip)) {
708 throw new BillingZipException();
709 }
710 else if (Validator.isNull(billingCountry)) {
711 throw new BillingCountryException();
712 }
713 else if (Validator.isNull(billingPhone)) {
714 throw new BillingPhoneException();
715 }
716
717 if (!shipToBilling) {
718 if (Validator.isNull(shippingFirstName)) {
719 throw new ShippingFirstNameException();
720 }
721 else if (Validator.isNull(shippingLastName)) {
722 throw new ShippingLastNameException();
723 }
724 else if (!Validator.isEmailAddress(shippingEmailAddress)) {
725 throw new ShippingEmailAddressException();
726 }
727 else if (Validator.isNull(shippingStreet)) {
728 throw new ShippingStreetException();
729 }
730 else if (Validator.isNull(shippingCity)) {
731 throw new ShippingCityException();
732 }
733 else if (Validator.isNull(shippingState)) {
734 throw new ShippingStateException();
735 }
736 else if (Validator.isNull(shippingZip)) {
737 throw new ShippingZipException();
738 }
739 else if (Validator.isNull(shippingCountry)) {
740 throw new ShippingCountryException();
741 }
742 else if (Validator.isNull(shippingPhone)) {
743 throw new ShippingPhoneException();
744 }
745 }
746
747 if (!shoppingPrefs.usePayPal() &&
748 (shoppingPrefs.getCcTypes().length > 0)) {
749
750 if (Validator.isNull(ccName)) {
751 throw new CCNameException();
752 }
753 else if (Validator.isNull(ccType)) {
754 throw new CCTypeException();
755 }
756 else if (!CreditCard.isValidNumber(ccNumber, ccType)) {
757 throw new CCNumberException();
758 }
759 else if (!CreditCard.isValidExpirationDate(ccExpMonth, ccExpYear)) {
760 throw new CCExpirationException();
761 }
762 }
763 }
764
765 }