Ejemplo n.º 1
0
 /**
  * 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);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Update saved shipping methods available for ShipperHQ
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     if ($this->shipperDataHelper->getConfigValue('carriers/shipper/active')) {
         $refreshResult = $this->shipperCarrier->refreshCarriers();
         if (array_key_exists('error', $refreshResult)) {
             $message = __($refreshResult['error']);
             $this->messageManager->addError($message);
         } else {
             $message = __('%1 carriers have been updated from ShipperHQ', count($refreshResult));
             $this->messageManager->addSuccess($message);
         }
     }
 }
 public function refreshConfig()
 {
     if ($this->shipperDataHelper->getCheckout()->getConfigUpdated()) {
         $this->storeManager->getStore()->resetConfig();
         $this->shipperDataHelper->getCheckout()->setConfigUpdated(false);
     }
 }
Ejemplo n.º 4
0
 public function getFormattedDate($date, $carrierGroupDetail)
 {
     $detail = $this->shipperDataHelper->decodeShippingDetails($carrierGroupDetail);
     $format = isset($detail[0]['display_date_format']) ? $detail[0]['display_date_format'] : $this->defaultDateFormat;
     $formattedDate = date($format, strtotime($date));
     return $formattedDate;
 }
Ejemplo n.º 5
0
 /**
  * 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);
         }
         //}
     }
 }
Ejemplo n.º 6
0
 public function toOptionArray()
 {
     $arr = [];
     $carriers = $this->shippingConfig->getAllCarriers($this->storeManager->getStore());
     foreach ($carriers as $carrierCode => $carrierModel) {
         $carrierTitle = $this->shipperDataHelper->getConfigValue('carriers/' . $carrierCode . '/title');
         if (strpos($carrierCode, 'shipper') === 0 || $carrierTitle == '') {
             continue;
         }
         if ($this->shipperDataHelper->getConfigValue('carriers/' . $carrierCode . '/model') == 'ShipperHQ\\Shipper\\Model\\Carrier\\Shipper') {
             continue;
         }
         $arr[] = ['value' => $carrierCode, 'label' => $carrierTitle];
     }
     array_unshift($arr, ['value' => false, 'label' => __('No Carrier')]);
     return $arr;
 }
 protected function getDefaultCarrierShipMethod($order, $shippingAddress)
 {
     $shipping_method = $order->getShippingMethod();
     $rate = $shippingAddress->getShippingRateByCode($shipping_method);
     if ($rate) {
         list($carrierCode, $method) = explode('_', $shipping_method, 2);
         $magentoCarrierCode = $this->shipperDataHelper->mapToMagentoCarrierCode($rate->getCarrierType(), $carrierCode);
         $shipping_method = $magentoCarrierCode . '_' . $method;
     }
     return $shipping_method;
 }
Ejemplo n.º 8
0
 /**
  * Enable or disable carrier
  * @return boolean
  */
 protected function tempSetCarrierEnabled($carrierCode, $enabled, $storeId)
 {
     $carrierPath = 'carriers/' . $carrierCode . '/active';
     $tempEnabledCarrier = false;
     if (!$this->shipperDataHelper->getConfigFlag($carrierPath) || !$enabled) {
         // if $enabled set to false was previously enabled!
         $this->mutableConfig->setValue($carrierPath, $enabled, 'store', $storeId);
         $tempEnabledCarrier = true;
     }
     return $tempEnabledCarrier;
 }
Ejemplo n.º 9
0
 /**
  * Set up additional attribute array
  * This takes the values from core_config_data
  *
  * Not currently implemented for v1 Magento2.
  *
  * @param $item
  * @return array
  */
 protected function getCustomAttributes($item)
 {
     $rawCustomAttributes = explode(',', $this->shipperDataHelper->getConfigValue('carriers/shipper/item_attributes'));
     $customAttributes = [];
     foreach ($rawCustomAttributes as $attribute) {
         $attribute = str_replace(' ', '', $attribute);
         if (!in_array($attribute, self::$stdAttributeNames) && !in_array($attribute, self::$legacyAttributeNames) && $attribute != '') {
             $customAttributes[] = $attribute;
         }
     }
     return self::populateAttributes($customAttributes, $item);
 }
Ejemplo n.º 10
0
 protected function getIsAttributeValueUsed($attribute_code, $value, $storeId, $isSelect = false)
 {
     $attributeModel = $this->shipperDataHelper->getAttribute($attribute_code, $storeId);
     $select = $this->connection->select()->distinct(true)->from($attributeModel->getBackend()->getTable(), ['value'])->where('attribute_id=?', $attributeModel->getId())->where('value!=?', '');
     $usedAttributeValues = $this->connection->fetchCol($select);
     if ($isSelect) {
         //account for multiselect values
         $separated = array();
         foreach ($usedAttributeValues as $key => $aValue) {
             if (strstr($aValue, ',')) {
                 $values = explode(',', $aValue);
                 $separated = array_merge($separated, $values);
                 unset($usedAttributeValues[$key]);
             }
         }
         $usedAttributeValues = array_merge($usedAttributeValues, $separated);
     }
     return in_array($value, $usedAttributeValues);
 }
Ejemplo n.º 11
0
 /**
  *
  * Build up an error message when no carrier rates returned
  * @return Mage_Shipping_Model_Rate_Result
  */
 protected function returnGeneralError($message = null)
 {
     $result = $this->rateFactory->create();
     $error = $this->_rateErrorFactory->create();
     $error->setCarrier($this->_code);
     $error->setCarrierTitle($this->getConfigData('title'));
     $error->setCarriergroupId('');
     if ($message && $this->shipperDataHelper->getConfigValue('carriers/shipper/debug')) {
         $error->setErrorMessage($message);
     } else {
         $error->setErrorMessage($this->getConfigData('specificerrmsg'));
     }
     $result->append($error);
     return $result;
 }
Ejemplo n.º 12
0
 /**
  * Define if debugging is enabled
  *
  * @return bool
  * @SuppressWarnings(PHPMD.BooleanGetMethodName)
  * @api
  */
 public function getDebugFlag()
 {
     return $this->shipperDataHelper->getConfigValue('carriers/shipper/debug');
 }