Skip to content

Commit

Permalink
Merge pull request #33 from wuunder/feature-picker-filtermapping
Browse files Browse the repository at this point in the history
added separated filter mapping for parcelshoppicker
  • Loading branch information
TimD90 authored Jun 13, 2019
2 parents f58e1e4 + 71c5c4f commit 960a290
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 19 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
78 changes: 63 additions & 15 deletions app/code/community/Wuunder/WuunderConnector/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public function processLabelInfo($infoArray)
} else {
$this->log("Bookingconfig not complete");
}

$this->log('API connection established');

if (empty($url)) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
}

Expand All @@ -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(
Expand All @@ -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) {
Expand Down Expand Up @@ -600,7 +649,6 @@ public function getOneStepValidationField($html)
}



/**
* Calculates total weight of a shipment.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/code/community/Wuunder/WuunderConnector/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config>
<modules>
<Wuunder_WuunderConnector>
<version>4.3.1</version>
<version>4.3.2</version>
</Wuunder_WuunderConnector>
</modules>
<global>
Expand Down

0 comments on commit 960a290

Please sign in to comment.