/**
  * updating the shipping details
  *
  * @param unknown $sender
  * @param unknown $param
  */
 public function updateShippingDetails($sender, $params)
 {
     $result = $error = $shippingInfoArray = array();
     try {
         Dao::beginTransaction();
         if (!isset($params->CallbackParameter->order) || !($order = Order::getByOrderNo($params->CallbackParameter->order->orderNo)) instanceof Order) {
             throw new Exception('System Error: invalid order passed in!');
         }
         if (!$order->getStatus() instanceof OrderStatus || trim($order->getStatus()->getId()) !== trim(OrderStatus::ID_PICKED)) {
             throw new Exception('System Error: Order [' . $order->getOrderNo() . '] Is Not is PICKED status. Current status is [' . ($order->getStatus() instanceof OrderStatus ? $order->getStatus()->getName() : 'NULL') . ']');
         }
         if (intval($order->getPassPaymentCheck()) !== 1) {
             throw new Exception('Error: there is no payment or payments has been cancelled!');
         }
         if (!isset($params->CallbackParameter->shippingInfo)) {
             throw new Exception('System Error: invalid Shipping Info Details passed in!');
         }
         $shippingInfo = $params->CallbackParameter->shippingInfo;
         if (!($courier = Courier::get($shippingInfo->courierId)) instanceof Courier) {
             throw new Exception('Invalid Courier Id [' . $shippingInfo->courierId . '] provided');
         }
         if (intval($order->getPassPaymentCheck()) !== 1) {
             throw new Exception('This ' . $order->getType() . ' has NOT pass payment check yet, please let the accounting department know before further actions!');
         }
         $notifyCust = isset($shippingInfo->notifyCust) && intval($shippingInfo->notifyCust) === 1 ? true : false;
         //$companyName = $shippingInfo->companyName;
         $contactName = $shippingInfo->contactName;
         $contactNo = $shippingInfo->contactNo;
         $shippingAddress = Address::create(trim($shippingInfo->street), trim($shippingInfo->city), trim($shippingInfo->region), trim($shippingInfo->country), trim($shippingInfo->postCode), trim($contactName), trim($contactNo));
         $shipment = Shippment::create($shippingAddress, $courier, trim($shippingInfo->conNoteNo), new UDate(), $order, $contactName, trim($contactNo), trim($shippingInfo->noOfCartons), '0', StringUtilsAbstract::getValueFromCurrency(trim($shippingInfo->actualShippingCost)), isset($shippingInfo->deliveryInstructions) ? trim($shippingInfo->deliveryInstructions) : '');
         $order->setStatus(OrderStatus::get(OrderStatus::ID_SHIPPED))->save();
         $result['shipment'] = $shipment->getJson();
         //add shipment information
         if ($notifyCust === true && $order->getIsFromB2B() === true) {
             $templateName = trim($shipment->getCourier()->getId()) === trim(Courier::ID_LOCAL_PICKUP) ? 'local_pickup' : $order->getStatus()->getName();
             $notificationMsg = trim(OrderNotificationTemplateControl::getMessage($templateName, $order));
             if ($notificationMsg !== '') {
                 B2BConnector::getConnector(B2BConnector::CONNECTOR_TYPE_SHIP, SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_WSDL), SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_USER), SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_KEY))->shipOrder($order, $shipment, array(), $notificationMsg, false, false);
                 //push the status of the order to SHIPPed
                 $emailToCustomer = trim($shipment->getCourier()->getId()) !== trim(Courier::ID_LOCAL_PICKUP);
                 B2BConnector::getConnector(B2BConnector::CONNECTOR_TYPE_ORDER, SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_WSDL), SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_USER), SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_KEY))->changeOrderStatus($order, $order->getStatus()->getMageStatus(), $notificationMsg, $emailToCustomer);
                 if ($emailToCustomer === true) {
                     $order->addComment('An email notification contains shippment information has been sent to customer for: ' . $order->getStatus()->getName(), Comments::TYPE_SYSTEM);
                 }
             }
         }
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $error[] = $ex->getMessage();
     }
     $params->ResponseData = StringUtilsAbstract::getJson($result, $error);
 }
Esempio n. 2
0
 /**
  *
  * @param unknown $sender
  * @param unknown $params
  * @throws Exception
  */
 public function addPayment($sender, $param)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         if (!isset($param->CallbackParameter->againstEntity) || !isset($param->CallbackParameter->againstEntity->entity) || !isset($param->CallbackParameter->againstEntity->entityId) || ($entityName = trim($param->CallbackParameter->againstEntity->entity)) === '' || !($entity = $entityName::get(trim($param->CallbackParameter->againstEntity->entityId))) instanceof $entityName) {
             throw new Exception('System Error: invalid Order or CreditNote provided. Can NOT get any payments at all.');
         }
         if (!$entity instanceof Order && !$entity instanceof CreditNote) {
             throw new Exception('System Error: you can ONLY add payments for a Order or a CreditNote');
         }
         if (!isset($param->CallbackParameter->payment) || !isset($param->CallbackParameter->payment->paidAmount) || ($paidAmount = StringUtilsAbstract::getValueFromCurrency(trim($param->CallbackParameter->payment->paidAmount))) === '' || !is_numeric($paidAmount)) {
             throw new Exception('System Error: invalid Paid Amount passed in!');
         }
         if (!isset($param->CallbackParameter->payment->payment_method_id) || ($paymentMethodId = trim($param->CallbackParameter->payment->payment_method_id)) === '' || !($paymentMethod = PaymentMethod::get($paymentMethodId)) instanceof PaymentMethod) {
             throw new Exception('System Error: invalid Payment Method passed in!');
         }
         $notifyCust = isset($param->CallbackParameter->payment->notifyCust) && intval($param->CallbackParameter->payment->notifyCust) === 1 ? true : false;
         $extraComment = '';
         if (!isset($param->CallbackParameter->payment->extraComments) || ($extraComment = trim($param->CallbackParameter->payment->extraComments)) === '') {
             throw new Exception('Some comments for this payment is required.');
         }
         //save the payment
         $newPayment = null;
         $entity = $entity->addPayment($paymentMethod, $paidAmount, $extraComment, new UDate(), $newPayment);
         $results['item'] = $newPayment->getJson();
         //notify the customer
         if ($entity instanceof Order && $notifyCust === true && $entity->getIsFromB2B() === true) {
             $notificationMsg = trim(OrderNotificationTemplateControl::getMessage('paid', $entity));
             if ($notificationMsg !== '') {
                 B2BConnector::getConnector(B2BConnector::CONNECTOR_TYPE_ORDER, SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_WSDL), SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_USER), SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_KEY))->changeOrderStatus($entity, OrderStatus::get(OrderStatus::ID_PICKED)->getMageStatus(), $notificationMsg, true);
                 $comments = 'An email notification contains payment checked info has been sent to customer for: ' . $entity->getStatus()->getName();
                 Comments::addComments($entity, $comments, Comments::TYPE_SYSTEM);
             }
         }
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }