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; }
protected function processRatesResponse($shipperResponse, $transactionId, $globals) { $carrierGroups = $shipperResponse->carrierGroups; $ratesArray = []; $timezone = $this->shipperDataHelper->getConfigValue('general/locale/timezone'); $configSetttings = $this->configSettingsFactory->create(['hideNotifications' => $this->shipperDataHelper->getConfigFlag('carriers/shipper/hide_notify'), 'transactionIdEnabled' => $this->shipperDataHelper->isTransactionIdEnabled(), 'locale' => $this->getLocaleInGlobals(), 'shipperHQCode' => $this->_code, 'shipperHQTitle' => $this->shipperDataHelper->getConfigFlag('carriers/shipper/title'), 'timezone' => $timezone]); $splitCarrierGroupDetail = []; foreach ($carrierGroups as $carrierGroup) { $carrierGroupDetail = $this->shipperRateHelper->extractCarrierGroupDetail($carrierGroup, $transactionId, $configSetttings); $this->setCarriergroupOnItems($carrierGroupDetail, $carrierGroup->products); //Pass off each carrier group to helper to decide best fit to process it. //Push result back into our array foreach ($carrierGroup->carrierRates as $carrierRate) { $this->carrierConfigHandler->saveCarrierResponseDetails($carrierRate, $carrierGroupDetail, false); $carrierResultWithRates = $this->shipperRateHelper->extractShipperHQRates($carrierRate, $carrierGroupDetail, $configSetttings, $splitCarrierGroupDetail); $ratesArray[] = $carrierResultWithRates; //push out event so other modules can save their data $this->eventManager->dispatch('shipperhq_carrier_rate_response_received', ['carrier_rate_response' => $carrierRate, 'carrier_group_detail' => $carrierGroupDetail]); } } //check for configuration here for display if ($shipperResponse->mergedRateResponse) { $mergedRatesArray = []; foreach ($shipperResponse->mergedRateResponse->carrierRates as $carrierRate) { $mergedResultWithRates = $this->shipperRateHelper->extractShipperHQMergedRates($carrierRate, $splitCarrierGroupDetail, $configSetttings, $transactionId); $mergedRatesArray[] = $mergedResultWithRates; } $ratesArray = $mergedRatesArray; } $carriergroupDescriber = $shipperResponse->globalSettings->carrierGroupDescription; if ($carriergroupDescriber != '') { $this->carrierConfigHandler->saveConfig($this->shipperDataHelper->getCarrierGroupDescPath(), $carriergroupDescriber); } $this->carrierConfigHandler->refreshConfig(); return $ratesArray; }