From 71c5c4f72940b78dff3f745d640470b133b7afb5 Mon Sep 17 00:00:00 2001 From: Timo Janssen Date: Thu, 13 Jun 2019 13:02:19 +0200 Subject: [PATCH] added separated filter mapping for parcelshoppicker --- CHANGELOG.md | 8 +- .../Block/ParcelshopsTable.php | 4 + .../Wuunder/WuunderConnector/Helper/Data.php | 78 +++++++++++++++---- .../Model/System/Config/Source/Carriers.php | 8 +- .../Wuunder/WuunderConnector/etc/config.xml | 2 +- 5 files changed, 81 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5abfc8b..894a2f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,13 @@ Please file changes under `Added`, `Changed`, `Deprecated`, `Removed`, `Fixed` o The format is based on [Keep a Changelog](http://keepachangelog.com/). ## Unreleased -## [4.3.1](https://github.com/wuunder/wuunder-webshopplugin-magento/releases/tag/4.3.0) - 2019-05-29 +## [4.3.2](https://github.com/wuunder/wuunder-webshopplugin-magento/releases/tag/4.3.2) - 2019-06-13 + +### Added +- Added separated filter mapping for parcelshop picker shipping method + + +## [4.3.1](https://github.com/wuunder/wuunder-webshopplugin-magento/releases/tag/4.3.1) - 2019-05-29 ### Fixed - Fixed correctly saving booking token diff --git a/app/code/community/Wuunder/WuunderConnector/Block/ParcelshopsTable.php b/app/code/community/Wuunder/WuunderConnector/Block/ParcelshopsTable.php index 8420eb2..6b4caf0 100644 --- a/app/code/community/Wuunder/WuunderConnector/Block/ParcelshopsTable.php +++ b/app/code/community/Wuunder/WuunderConnector/Block/ParcelshopsTable.php @@ -14,6 +14,10 @@ public function _prepareToRender() 'label' => Mage::helper('wuunderconnector/data')->__('Name in checkout'), 'style' => 'width:100px', )); + $this->addColumn('filter', array( + 'label' => Mage::helper('wuunderconnector/data')->__('Wuunder filter'), + 'style' => 'width:100px', + )); $this->_addAfter = false; } diff --git a/app/code/community/Wuunder/WuunderConnector/Helper/Data.php b/app/code/community/Wuunder/WuunderConnector/Helper/Data.php index 08ba9de..6950463 100755 --- a/app/code/community/Wuunder/WuunderConnector/Helper/Data.php +++ b/app/code/community/Wuunder/WuunderConnector/Helper/Data.php @@ -230,7 +230,7 @@ public function processLabelInfo($infoArray) } else { $this->log("Bookingconfig not complete"); } - + $this->log('API connection established'); if (empty($url)) { @@ -281,7 +281,8 @@ public function processDataFromApi($wuunderApiResult, $orderId, $booking_token) return true; } - public function processTrackingDataFromApi($carrierCode, $trackingCode, $orderId, $bookingToken) { + public function processTrackingDataFromApi($carrierCode, $trackingCode, $orderId, $bookingToken) + { $shipment = Mage::getModel('wuunderconnector/wuundershipment'); $shipment->load(intval($orderId), 'order_id'); if (!$shipment) { @@ -373,13 +374,66 @@ public function buildWuunderData($infoArray, $order, $bookingToken) } } + $parcelshopId = null; + if ($order->getShippingMethod() == 'wuunderparcelshop_wuunderparcelshop') { + $parcelshopId = Mage::helper('wuunderconnector/parcelshophelper')->getParcelshopIdForQuote($order->getQuoteId()); + } + $shipping_method = $order->getShippingMethod(); $preferredServiceLevel = ""; - $shippingMethodCount = 5; - for ($i = 1; $i <= $shippingMethodCount; $i++) { - if ($shipping_method === Mage::getStoreConfig('wuunderconnector/connect/filterconnect' . $i . '_value')) { - $preferredServiceLevel = Mage::getStoreConfig('wuunderconnector/connect/filterconnect' . $i . '_name'); - break; + if ($shipping_method === "wuunderparcelshop_wuunderparcelshop") { + $carriersFilters = array(); + $carrierData = Mage::getStoreConfig('carriers/wuunderparcelshop/parcelshop_carriers'); + if (!empty($carrierData)) { + $carrierData = unserialize($carrierData); + foreach ($carrierData as $carrier) { + array_push($carriers, $carrier['carrier']); + $carriersFilters[$carrier['carrier']] = $carrier['filter']; + } + } + $mapping = array( + 'DHL_PARCEL' => 'dhl', + 'dpd' => 'dpd', + 'POST_NL' => 'postnl' + ); + + if (!empty($parcelshopId)) { + $storeId = Mage::app()->getStore()->getStoreId(); + $connector = new Wuunder\Connector($this->getAPIKey($storeId), Mage::getStoreConfig('wuunderconnector/connect/testmode', $storeId) == 1); + $parcelshopDataRequest = $connector->getParcelshopById(); + $config = new \Wuunder\Api\Config\ParcelshopConfig(); + $config->setId($parcelshopId); + + if ($config->validate()) { + $parcelshopDataRequest->setConfig($config); + + if ($parcelshopDataRequest->fire()) { + $response = $parcelshopDataRequest->getParcelshopResponse()->getBody(); + + try { + $parcelshopCarrier = json_decode($response)->provider; + } catch (Exception $e) { + $parcelshopCarrier = ""; + } + + if (array_key_exists($mapping[$parcelshopCarrier], $carriersFilters)) { + $preferredServiceLevel = $carriersFilters[$mapping[$parcelshopCarrier]]; + } + } else { + Mage::helper('wuunderconnector/data')->log('ERROR saveWuunderShipment : ' . json_encode($parcelshopDataRequest->getParcelshopResponse()->getError())); + } + } else { + print("Parcelshopconfig not valid"); + } + } + + } else { + $shippingMethodCount = 5; + for ($i = 1; $i <= $shippingMethodCount; $i++) { + if ($shipping_method === Mage::getStoreConfig('wuunderconnector/connect/filterconnect' . $i . '_value')) { + $preferredServiceLevel = Mage::getStoreConfig('wuunderconnector/connect/filterconnect' . $i . '_name'); + break; + } } } @@ -396,15 +450,10 @@ public function buildWuunderData($infoArray, $order, $bookingToken) } - $parcelshopId = null; - if ($order->getShippingMethod() == 'wuunderparcelshop_wuunderparcelshop') { - $parcelshopId =Mage::helper('wuunderconnector/parcelshophelper')->getParcelshopIdForQuote($order->getQuoteId()); - } - $sourceObj = array( "product" => "Magento 1 extension", "version" => array( - "build" => "4.3.1", + "build" => "4.3.2", "plugin" => "4.0" ), "platform" => array( @@ -430,7 +479,7 @@ public function buildWuunderData($infoArray, $order, $bookingToken) $bookingConfig->setWeight(intval($infoArray['weight'])); $bookingConfig->setCustomerReference($order->getIncrementId()); $bookingConfig->setPreferredServiceLevel($preferredServiceLevel); - $bookingConfig->setSource($sourceObj); + $bookingConfig->setSource($sourceObj); $bookingConfig->setDeliveryAddress($customerAdr); $bookingConfig->setPickupAddress($webshopAdr); if ($parcelshopId) { @@ -600,7 +649,6 @@ public function getOneStepValidationField($html) } - /** * Calculates total weight of a shipment. * diff --git a/app/code/community/Wuunder/WuunderConnector/Model/System/Config/Source/Carriers.php b/app/code/community/Wuunder/WuunderConnector/Model/System/Config/Source/Carriers.php index 73589a2..3d074f5 100644 --- a/app/code/community/Wuunder/WuunderConnector/Model/System/Config/Source/Carriers.php +++ b/app/code/community/Wuunder/WuunderConnector/Model/System/Config/Source/Carriers.php @@ -12,7 +12,9 @@ public function getAllOptions() if(!$_title = Mage::getStoreConfig("carriers/$_code/title")) $_title = $_code; - $options[] = array('value' => $_code."_".$_code, 'label' => $_title . " ($_code)"); + if ($_code !== "wuunderparcelshop") { + $options[] = array('value' => $_code . "_" . $_code, 'label' => $_title . " ($_code)"); + } } if(false) @@ -34,7 +36,9 @@ public function toOptionArray() if(!$_title = Mage::getStoreConfig("carriers/$_code/title")) $_title = $_code; - $options[] = array('value' => $_code."_".$_code, 'label' => $_title . " ($_code)"); + if ($_code !== "wuunderparcelshop") { + $options[] = array('value' => $_code . "_" . $_code, 'label' => $_title . " ($_code)"); + } } if(false) diff --git a/app/code/community/Wuunder/WuunderConnector/etc/config.xml b/app/code/community/Wuunder/WuunderConnector/etc/config.xml index 8518b88..c23692e 100755 --- a/app/code/community/Wuunder/WuunderConnector/etc/config.xml +++ b/app/code/community/Wuunder/WuunderConnector/etc/config.xml @@ -2,7 +2,7 @@ - 4.3.1 + 4.3.2