protected function updateAll($updateData)
 {
     $result = 0;
     foreach ($updateData as $attributeUpdate) {
         if ($attributeUpdate['attribute_type'] == 'product') {
             if ($attributeUpdate['status'] == self::ADD_ATTRIBUTE_OPTION) {
                 $optionToAdd = $this->optionDataFactory->create();
                 $optionToAdd->setLabel($attributeUpdate['value'])->setSortOrder(0)->setIsDefault(0);
                 try {
                     $this->attributeOptionManagement->add($attributeUpdate['attribute_code'], $optionToAdd);
                     $result++;
                 } catch (\Exception $e) {
                     $this->shipperLogger->postInfo('Shipperhq_Shipper', 'Unable to add attribute option', 'Error: ' . $e->getMessage());
                     $result = false;
                 }
             } else {
                 if ($attributeUpdate['status'] == self::AUTO_REMOVE_ATTRIBUTE_OPTION) {
                     try {
                         $this->attributeOptionManagement->delete($attributeUpdate['attribute_code'], $attributeUpdate['option_id']);
                         $result++;
                     } catch (\Exception $e) {
                         $this->shipperLogger->postInfo('Shipperhq_Shipper', 'Unable to remove attribute option', 'Error: ' . $e->getMessage());
                         $result = false;
                     }
                 }
             }
         } elseif ($attributeUpdate['attribute_type'] == 'global_setting') {
             $this->carrierConfigHandler->saveConfig('carriers/shipper/' . $attributeUpdate['attribute_code'], $attributeUpdate['value']);
         }
     }
     if ($result >= 0) {
         $this->checkSynchStatus(true);
     }
     return $result;
 }
 /**
  * Get backup carrier if configured
  * @return mixed
  */
 protected function retrieveBackupCarrier($backupCarrierDetails)
 {
     $this->shipperLogger->postInfo('Shipperhq_Shipper', 'Unable to establish connection with ShipperHQ', 'Attempting to use backup carrier: ' . $backupCarrierDetails);
     if (!$backupCarrierDetails) {
         $this->shipperLogger->postDebug('Shipperhq_Shipper', 'Backup carrier: ', 'No backup carrier is configured');
         return false;
     }
     return $backupCarrierDetails;
 }
 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();
 }
Beispiel #4
0
 /**
  *
  * Generate error message from ShipperHQ response.
  * Display of error messages per carrier is managed in SHQ configuration
  *
  * @param $result
  * @param $errorDetails
  * @return Mage_Shipping_Model_Rate_Result
  */
 protected function appendError($result, $errorDetails, $carrierCode, $carrierTitle, $carrierGroupId = null, $carrierGroupDetail = null)
 {
     if (is_object($errorDetails)) {
         $errorDetails = get_object_vars($errorDetails);
     }
     if (array_key_exists('internalErrorMessage', $errorDetails) && $errorDetails['internalErrorMessage'] != '' || array_key_exists('externalErrorMessage', $errorDetails) && $errorDetails['externalErrorMessage'] != '') {
         $errorMessage = false;
         if ($this->getConfigData("debug") && array_key_exists('internalErrorMessage', $errorDetails) && $errorDetails['internalErrorMessage'] != '') {
             $errorMessage = $errorDetails['internalErrorMessage'];
         } else {
             if (array_key_exists('externalErrorMessage', $errorDetails) && $errorDetails['externalErrorMessage'] != '') {
                 $errorMessage = $errorDetails['externalErrorMessage'];
             }
         }
         if (array_key_exists('externalErrorMessage', $errorDetails) && $errorDetails['externalErrorMessage'] != '') {
             $errorMessage = $errorDetails['externalErrorMessage'];
         }
         if ($errorMessage) {
             $error = $this->_rateErrorFactory->create();
             $error->setCarrier($carrierCode);
             $error->setCarrierTitle($carrierTitle);
             $error->setErrorMessage($errorMessage);
             if (!is_null($carrierGroupId)) {
                 $error->setCarriergroupId($carrierGroupId);
             }
             if (is_array($carrierGroupDetail) && array_key_exists('checkoutDescription', $carrierGroupDetail)) {
                 $error->setCarriergroup($carrierGroupDetail['checkoutDescription']);
             }
             $result->append($error);
             $this->shipperLogger->postInfo('Shipperhq_Shipper', 'Shipper HQ returned error', $errorDetails);
         }
     }
     return $result;
 }