Exemplo n.º 1
0
 public function getCarriergroupInfo()
 {
     $order = $this->getOrder();
     if (is_null($this->cgInfo)) {
         $this->cgInfo = $this->carrierGroupHelper->getOrderCarrierGroupInfo($order->getId());
         if (empty($this->cgInfo)) {
             //retrieve using quote shipping address ID from carrier group helper
             //legacy
             $this->cgInfo = $this->shipperDataHelper->decodeShippingDetails($order->getCarriergroupShippingDetails());
         }
     }
     return $this->cgInfo;
 }
Exemplo n.º 2
0
 /**
  * Prepare Data Source
  *
  * @param array $dataSource
  * @return array
  */
 public function prepareDataSource(array $dataSource)
 {
     if (isset($dataSource['data']['items'])) {
         foreach ($dataSource['data']['items'] as &$item) {
             $orderGridDetails = $this->carrierGroupHelper->loadOrderGridDetailByOrderId($item["entity_id"]);
             foreach ($orderGridDetails as $orderDetail) {
                 if ($orderDetail->getCarrierGroup()) {
                     $item[$this->getData('name')] = $orderDetail->getCarrierGroup();
                 }
             }
         }
     }
     return $dataSource;
 }
 /**
  * Process shipping method and save
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     if ($this->shipperDataHelper->getConfigValue('carriers/shipper/active')) {
         $request = $observer->getEvent()->getRequest();
         $shippingMethods = $request->getPost('shipping_method', '');
         if (!is_array($shippingMethods)) {
             return;
         }
         foreach ($shippingMethods as $addressId => $shippingMethod) {
             if (empty($shippingMethod)) {
                 return;
             }
             $quote = $observer->getEvent()->getQuote();
             $addresses = $quote->getAllShippingAddresses();
             $shippingAddress = false;
             foreach ($addresses as $address) {
                 if ($address->getId() == $addressId) {
                     $shippingAddress = $address;
                     break;
                 }
             }
             $this->carrierGroupHelper->saveCarrierGroupInformation($shippingAddress, $shippingMethod);
         }
     }
 }
 /**
  * Record order shipping information after order is placed
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     if ($this->shipperDataHelper->getConfigValue('carriers/shipper/active')) {
         $requestData = $observer->getRequestModel()->getPost();
         if (isset($requestData['order'])) {
             $orderData = $requestData['order'];
         }
         $quote = $observer->getSession()->getQuote();
         //if(!empty($orderData['shipping_method_flag']))
         if (!empty($orderData['shipping_method'])) {
             $shippingMethod = $orderData['shipping_method'];
             $this->carrierGroupHelper->saveCarrierGroupInformation($quote->getShippingAddress(), $shippingMethod);
         }
         //}
     }
 }
Exemplo n.º 5
0
 /**
  * Prepare Data Source
  *
  * @param array $dataSource
  * @return array
  */
 public function prepareDataSource(array $dataSource)
 {
     if (isset($dataSource['data']['items'])) {
         foreach ($dataSource['data']['items'] as &$item) {
             $item[$this->getData('name')] = NULL;
             $orderGridDetails = $this->carrierGroupHelper->loadOrderGridDetailByOrderId($item["entity_id"]);
             foreach ($orderGridDetails as $orderDetail) {
                 if ($orderDetail->getDeliveryDate() != '') {
                     $deliveryDate = $orderDetail->getDeliveryDate();
                     $date = $this->timezone->date(new \DateTime($deliveryDate));
                     if (isset($this->getConfiguration()['timezone']) && !$this->getConfiguration()['timezone']) {
                         $date = new \DateTime($deliveryDate);
                     }
                     $item[$this->getData('name')] = $date->format('Y-m-d H:i:s');
                 }
             }
         }
     }
     return $dataSource;
 }
 protected function recordOrder($order)
 {
     $customOrderId = null;
     //https://github.com/magento/magento2/issues/4233
     $quoteId = $order->getQuoteId();
     $quote = $this->quoteRepository->get($quoteId);
     $shippingAddress = $quote->getShippingAddress();
     $carrierType = $shippingAddress->getCarrierType();
     //  $order->setCarrierType($carrierType);
     $order->setDestinationType($shippingAddress->getDestinationType());
     $order->setValidationStatus($shippingAddress->getValidationStatus());
     $this->carrierGroupHelper->saveOrderDetail($order, $shippingAddress);
     $this->carrierGroupHelper->recordOrderItems($order);
     $this->packageHelper->saveOrderPackages($order, $shippingAddress);
     if (strstr($order->getShippingMethod(), 'shqshared_')) {
         $orderDetailArray = $this->carrierGroupHelper->loadOrderDetailByOrderId($order->getId());
         //SHQ16- Review for splits
         foreach ($orderDetailArray as $orderDetail) {
             $original = $orderDetail->getCarrierType();
             $carrierTypeArray = explode('_', $orderDetail->getCarrierType());
             if (is_array($carrierTypeArray)) {
                 $orderDetail->setCarrierType($carrierTypeArray[1]);
                 //SHQ16-1026
                 $currentShipDescription = $order->getShippingDescription();
                 $shipDescriptionArray = explode('-', $currentShipDescription);
                 $cgArray = $this->shipperDataHelper->decodeShippingDetails($orderDetail->getCarrierGroupDetail());
                 foreach ($cgArray as $key => $cgDetail) {
                     if (isset($cgDetail['carrierType']) && $cgDetail['carrierType'] == $original) {
                         $cgDetail['carrierType'] = $carrierTypeArray[1];
                     }
                     if (is_array($shipDescriptionArray) && isset($cgDetail['carrierTitle'])) {
                         $shipDescriptionArray[0] = $cgDetail['carrierTitle'] . ' ';
                         $newShipDescription = implode('-', $shipDescriptionArray);
                         $order->setShippingDescription($newShipDescription);
                     }
                     $cgArray[$key] = $cgDetail;
                 }
                 $encoded = $this->shipperDataHelper->encode($cgArray);
                 $orderDetail->setCarrierGroupDetail($encoded);
                 $orderDetail->save();
             }
             $this->shipperLogger->postInfo('Shipperhq_Shipper', 'Rates displayed as single carrier', 'Resetting carrier type on order to be ' . $carrierTypeArray[1]);
         }
     }
     if ($this->shipperDataHelper->useDefaultCarrierCodes()) {
         $order->setShippingMethod($this->getDefaultCarrierShipMethod($order, $shippingAddress));
     }
     $order->save();
 }
Exemplo n.º 7
0
 /**
  * Prepare Data Source
  *
  * @param array $dataSource
  * @return array
  */
 public function prepareDataSource(array $dataSource)
 {
     if (isset($dataSource['data']['items'])) {
         foreach ($dataSource['data']['items'] as &$item) {
             $orderGridDetails = $this->carrierGroupHelper->loadOrderGridDetailByOrderId($item["entity_id"]);
             foreach ($orderGridDetails as $orderDetail) {
                 if ($orderDetail->getTimeSlot()) {
                     $timeslot = $orderDetail->getTimeSlot();
                     if ($timeslot) {
                         if (strstr($timeslot, '_')) {
                             list($start, $end) = explode('_', $timeslot, 2);
                         } else {
                             $start = $timeslot;
                         }
                     } else {
                         $start = null;
                     }
                     $item[$this->getData('name')] = $start;
                 }
             }
         }
     }
     return $dataSource;
 }
 /**
  *Set additional information for shipping address
  *
  * @param \Magento\Checkout\Model\ShippingInformationManagement $subject
  * @param callable $proceed
  *
  * @return \Magento\Checkout\Api\Data\PaymentDetailsInterface $paymentDetails
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function aroundSaveAddressInformation(\Magento\Checkout\Model\ShippingInformationManagement $subject, $proceed, $cartId, \Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation)
 {
     try {
         $carrierCode = $addressInformation->getShippingCarrierCode();
         $methodCode = $addressInformation->getShippingMethodCode();
         $shippingMethod = $carrierCode . '_' . $methodCode;
         $quote = $this->quoteRepository->getActive($cartId);
         $address = $quote->getShippingAddress();
         $validation = $this->checkoutSession->getShipAddressValidation();
         if (is_array($validation) && isset($validation['key'])) {
             if (isset($validation['validation_status'])) {
                 $additionalDetail['address_valid'] = $validation['validation_status'];
                 $address->setValidationStatus($validation['validation_status']);
             }
             if (isset($validation['destination_type'])) {
                 $additionalDetail['destination_type'] = $validation['destination_type'];
                 $address->setDestinationType($validation['destination_type']);
             }
             $this->checkoutSession->setShipAddressValidation(null);
         }
         $address->save();
         $additionalDetail = new \Magento\Framework\DataObject();
         $extAttributes = $addressInformation->getShippingAddress()->getExtensionAttributes();
         //push out event so other modules can save their data TODO add carrier_group_id
         $this->eventManager->dispatch('shipperhq_additional_detail_checkout', ['address_extn_attributes' => $extAttributes, 'additional_detail' => $additionalDetail, 'carrier_code' => $carrierCode]);
         $additionalDetailArray = $additionalDetail->convertToArray();
         $this->shipperLogger->postDebug('ShipperHQ Shipper', 'processing additional detail ', $additionalDetail);
         $this->carrierGroupHelper->saveCarrierGroupInformation($address, $shippingMethod, $additionalDetailArray);
     } catch (\Exception $e) {
         $this->shipperLogger->postCritical('Shipperhq_Shipper', 'Shipping Information Plugin', 'Exception raised ' . $e->getMessage());
     }
     $result = $proceed($cartId, $addressInformation);
     if ($address->getCustomerId()) {
         $customerAddresses = $quote->getCustomer()->getAddresses();
         foreach ($customerAddresses as $oneAddress) {
             if ($oneAddress->getId() == $address->getCustomerAddressId()) {
                 if ($address->getValidationStatus()) {
                     $oneAddress->setCustomAttribute('validation_status', $address->getValidationStatus());
                 }
                 if ($address->getDestinationType()) {
                     $oneAddress->setCustomAttribute('destination_type', $address->getDestinationType());
                 }
                 $this->addressRepository->save($oneAddress);
             }
         }
     }
     return $result;
 }
Exemplo n.º 9
0
 protected function setCarriergroupOnItems($carriergroupDetails, $productInRateResponse)
 {
     $rateItems = [];
     foreach ($productInRateResponse as $item) {
         $item = (array) $item;
         $rateItems[$item['sku']] = $item['qty'];
     }
     foreach ($this->rawRequest->getAllItems() as $quoteItem) {
         if (array_key_exists($quoteItem->getSku(), $rateItems)) {
             $quoteItem->setCarriergroupId($carriergroupDetails['carrierGroupId']);
             $quoteItem->setCarriergroup($carriergroupDetails['name']);
             if ($quoteItem->getQuoteItemId()) {
                 //need to work out how to distinguish between quote address items on multi address checkout
             }
             $this->carrierGroupHelper->saveCarrierGroupItem($quoteItem, $carriergroupDetails['carrierGroupId'], $carriergroupDetails['name']);
         }
     }
 }