diff --git a/README.md b/README.md
index 825703fb..d52e7268 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ The new 3.0 version fixes several core issues (incorrect/missing order address,
* Enable direct Order Search by ID
* Access Order Messages and Notes
-Dowload the latest version of the extension at: https://github.com/agnostack/magento_extension/releases/tag/v3.0.0.
+Dowload the latest version of the extension at: https://github.com/agnostack/magento_extension/releases/tag/v3.0.1.
Additional detailed instructions on configuring agnoStack for the new version can be found at: https://agnostack.com/faqs/setup-onboarding/configuring-magento-1.
diff --git a/src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Config/Buttons/Signup.php b/src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Config/Buttons/Signup.php
index 95cb36d6..6fc3662f 100644
--- a/src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Config/Buttons/Signup.php
+++ b/src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Config/Buttons/Signup.php
@@ -37,48 +37,11 @@ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
$originalData = $element->getOriginalData();
$this->addData(array(
'button_label' => Mage::helper('zendesk')->__($originalData['button_label']),
+ 'button_url' => Mage::helper('zendesk')->__($originalData['button_url']),
'html_id' => $element->getHtmlId(),
'url' => Mage::getSingleton('adminhtml/url')->getUrl('*/setup/start')
));
return $this->_toHtml();
}
-
- public function getPostUrl()
- {
- return Mage::helper('zendesk')->getProvisionUrl();
- }
-
- public function getPostInfo()
- {
- $websiteCode = Mage::app()->getRequest()->getParam('website');
- if ($websiteCode) {
- $website = Mage::getModel('core/website')->load($websiteCode);
- } else {
- $website = Mage::getModel('core/website')->getCollection()
- ->addFieldToFilter('is_default', 1)
- ->getFirstItem();
- }
-
- $storeCode = Mage::app()->getRequest()->getParam('store');
- if ($storeCode) {
- $store = Mage::getModel('core/store')->load($storeCode);
- } else {
- $store = $website->getDefaultStore();
- }
-
- $info = array(
- 'magento_domain' => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB),
- 'magento_current_user_id' => Mage::getSingleton('admin/session')->getUser()->getUserId(),
- 'magento_user_count' => Mage::getModel('admin/user')->getCollection()->getSize(),
- 'magento_auth_token' => Mage::helper('zendesk')->getProvisionToken(true),
- 'magento_callback' => Mage::helper('adminhtml')->getUrl('adminhtml/zendesk/redirect', array('type' => 'settings', 'id' => 'zendesk')),
- 'magento_locale' => Mage::getStoreConfig('general/locale/code'),
- 'magento_timezone' => Mage::getStoreConfig('general/locale/timezone'),
- 'magento_api_url' => Mage::getUrl('zendesk/api', array('_store' => $store->getCode())),
- 'magento_store_name' => $website->getName(),
- );
-
- return $info;
- }
}
diff --git a/src/app/code/community/Zendesk/Zendesk/Helper/Data.php b/src/app/code/community/Zendesk/Zendesk/Helper/Data.php
index c3044899..5202c120 100644
--- a/src/app/code/community/Zendesk/Zendesk/Helper/Data.php
+++ b/src/app/code/community/Zendesk/Zendesk/Helper/Data.php
@@ -154,46 +154,6 @@ public function setApiToken($token = null)
return $token;
}
- /**
- * Returns the provisioning endpoint for new setups.
- *
- * This uses the config/zendesk/provision_url XML path to retrieve the setting, with a default value set in
- * the extension config.xml file. This can be overridden in your website's local.xml file.
- * @return null|string URL or null on failure
- */
- public function getProvisionUrl()
- {
- $config = Mage::getConfig();
- $data = $config->getNode('zendesk/provision_url');
- if(!$data) {
- return null;
- }
- return (string)$data;
- }
-
- public function getProvisionToken($generate = false)
- {
- $token = Mage::getStoreConfig('zendesk/hidden/provision_token', 0);
-
- if( (!$token || strlen(trim($token)) == 0) && $generate) {
- $token = $this->setProvisionToken();
- }
-
- return $token;
- }
-
- public function setProvisionToken($token = null)
- {
- if(!$token) {
- $token = hash('sha256', Mage::helper('oauth')->generateToken());
- }
-
- Mage::getModel('core/config')->saveConfig('zendesk/hidden/provision_token', $token, 'default');
- Mage::getConfig()->removeCache();
-
- return $token;
- }
-
public function getOrderDetail($order)
{
// if the admin site has a custom URL, use it
@@ -479,24 +439,26 @@ protected function formatCustomer($order)
protected function formatAddress($address)
{
- $addressData = array(
- 'type' => 'address',
- 'first_name' => $address->getFirstname(),
- 'last_name' => $address->getLastname(),
- 'city' => $address->getCity(),
- 'county' => $address->getRegion(),
- 'postcode' => $address->getPostcode(),
- 'country' => $address->getCountryId(),
- 'phone' => $address->getTelephone()
- );
-
- $entityId = $address->getEntityId();
- $addressId = $address->getCustomerAddressId();
- $addressData['id'] = $addressId ?: $entityId;
-
- $street = $address->getStreet();
- $addressData['line_1'] = $street[0] ?: '';
- $addressData['line_2'] = $street[1] ?: '';
+ if ($address) {
+ $addressData = array(
+ 'type' => 'address',
+ 'first_name' => $address->getFirstname(),
+ 'last_name' => $address->getLastname(),
+ 'city' => $address->getCity(),
+ 'county' => $address->getRegion(),
+ 'postcode' => $address->getPostcode(),
+ 'country' => $address->getCountryId(),
+ 'phone' => $address->getTelephone()
+ );
+
+ $entityId = $address->getEntityId();
+ $addressId = $address->getCustomerAddressId();
+ $addressData['id'] = $addressId ?: $entityId;
+
+ $street = $address->getStreet();
+ $addressData['line_1'] = $street[0] ?: '';
+ $addressData['line_2'] = $street[1] ?: '';
+ }
return $addressData;
}
@@ -505,44 +467,52 @@ public function getShipments($order)
{
$shipments = array();
$orderStatus = $order->getStatus();
+ $serviceCode = $order->getShippingDescription();
+ $tracks = $order->getTracksCollection();
+ $shippingMethod = $order->getShippingMethod();
+ $orderShippingAddress = $order->getShippingAddress();
foreach($order->getShipmentsCollection() as $shipment) {
$shipmentId = $shipment->getEntityId();
$shippingAddress = $shipment->getShippingAddress();
- $serviceCode = $order->getShippingDescription();
- }
-
- if ($shipmentId) {
- $tracks = $order->getTracksCollection();
- if (count($tracks) > 0) {
- foreach($tracks as $track) {
- if ($shipmentId == $track->getParentId()) {
- $shipments[] = array(
- 'id' => $track->getEntityId(),
- 'carrier' => $track->getTitle(),
- 'carrier_code' => $track->getCarrierCode(),
- 'service_code' => $serviceCode,
- 'shipping_description' => $track->getDescription() ?: '',
- 'created_at' => $track->getCreatedAt(),
- 'updated_at' => $track->getUpdatedAt(),
- 'tracking_number' => $track->getTrackNumber(),
- 'shipping_address' => $this->formatAddress($shippingAddress),
- 'order_status' => $orderStatus,
- );
+ if ($shipmentId) {
+ if (count($tracks) > 0) {
+ foreach($tracks as $track) {
+ if ($shipmentId == $track->getParentId()) {
+ $shipment = array(
+ 'id' => $track->getEntityId(),
+ 'carrier' => $track->getTitle(),
+ 'carrier_code' => $track->getCarrierCode(),
+ 'service_code' => $serviceCode,
+ 'shipping_description' => $track->getDescription() ?: '',
+ 'created_at' => $track->getCreatedAt(),
+ 'updated_at' => $track->getUpdatedAt(),
+ 'tracking_number' => $track->getTrackNumber(),
+ 'order_status' => $orderStatus,
+ );
+ if ($shippingAddress) {
+ $shipment['shipping_address'] = $this->formatAddress($shippingAddress);
+ }
+ $shipments[] = $shipment;
+ }
+ }
+ } else {
+ $shipment = array(
+ 'service_code' => $serviceCode,
+ 'carrier_code' => $shippingMethod,
+ 'order_status' => $orderStatus,
+ );
+ if ($shippingAddress) {
+ $shipment['shipping_address'] = $this->formatAddress($shippingAddress);
}
+ $shipments[] = $shipment;
}
- } else {
- $shipments[] = array(
- 'service_code' => $serviceCode,
- 'carrier_code' => $order->getShippingMethod(),
- 'shipping_address' => $this->formatAddress($shippingAddress),
- 'order_status' => $orderStatus,
- );
}
- } else {
- $shippingAddress = $order->getShippingAddress();
+ }
+
+ if (empty($shipments) && $orderShippingAddress) {
$shipments[] = array(
- 'shipping_address' => $this->formatAddress($shippingAddress),
+ 'shipping_address' => $this->formatAddress($orderShippingAddress),
);
}
@@ -558,13 +528,13 @@ public function getOrderDetailBasic($order)
$shippingAddress = $order->getShippingAddress();
$shippingWithTax = $order->getShippingInclTax();
$shippingMethod = $order->getShippingMethod();
+ $billingAddress = $order->getBillingAddress();
$orderInfo = array(
'id' => $order->getIncrementId(),
'url' => $urlModel->getUrl('adminhtml/sales_order/view', array('order_id' => $order->getId())),
'transaction_id' => $order->getIncrementId(),
'status' => $order->getStatus(),
- 'billing_address' => $this->formatAddress($order->getBillingAddress()),
'meta' => array(
'store_info' => array(
'type' => 'store_info',
@@ -572,8 +542,8 @@ public function getOrderDetailBasic($order)
),
'display_price' => array(
'with_tax' => $this->formatPrice($order->getGrandTotal(), $currency),
- 'without_tax' => $this->formatPrice($order->getGrandTotal() - $order->getTaxAmount(), $currency), // TODO: get without tax
- 'tax' => $this->formatPrice($order->getTaxAmount(), $currency) // TODO: get tax
+ 'without_tax' => $this->formatPrice($order->getGrandTotal() - $order->getTaxAmount(), $currency),
+ 'tax' => $this->formatPrice($order->getTaxAmount(), $currency)
),
'timestamps' => array(
'created_at' => $order->getCreatedAt(),
@@ -590,9 +560,12 @@ public function getOrderDetailBasic($order)
),
'shipments' => array(),
);
+ if ($billingAddress) {
+ $orderInfo['billing_address'] = $this->formatAddress($billingAddress);
+ }
foreach($order->getItemsCollection(array(), true) as $item) {
- $itemWithTax = $item->getRowTotal();
+ $itemWithoutTax = $item->getRowTotal();
$itemTax = $item->getTaxAmount();
$productId = $item->getProductId();
@@ -610,8 +583,8 @@ public function getOrderDetailBasic($order)
'refunded' => intval($item->getQtyRefunded()),
'meta' => array(
'display_price' => array(
- 'with_tax' => $this->formatPrice($itemWithTax, $currency),
- 'without_tax' => $this->formatPrice($itemWithTax - $itemTax, $currency),
+ 'with_tax' => $this->formatPrice($itemWithoutTax + $itemTax, $currency),
+ 'without_tax' => $this->formatPrice($itemWithoutTax, $currency),
'tax' => $this->formatPrice($iitemTax, $currency)
),
'timestamps' => array(
@@ -772,7 +745,9 @@ public function getCustomer($customer)
);
foreach($customer->getAddressesCollection() as $address) {
- $info['addresses'][] = $this->formatAddress($address);
+ if ($address) {
+ $info['addresses'][] = $this->formatAddress($address);
+ }
}
return $info;
@@ -825,7 +800,7 @@ public function getFilteredOrdersByProduct($customerFilters, $productFilters)
);
}
- if($email) {
+ if ($email) {
$filteredOrdersData = array_filter(array_values($ordersData), function ($orderData) use ($email) {
return ($orderData['email'] == $email);
});
diff --git a/src/app/code/community/Zendesk/Zendesk/controllers/ApiController.php b/src/app/code/community/Zendesk/Zendesk/controllers/ApiController.php
index d0a255cd..54dc0e1f 100644
--- a/src/app/code/community/Zendesk/Zendesk/controllers/ApiController.php
+++ b/src/app/code/community/Zendesk/Zendesk/controllers/ApiController.php
@@ -23,7 +23,7 @@ public function preDispatch() {
// TODO!!!!!!!: read version from config.xml
// $configSettings = Mage::getSingleton('Zendesk_Zendesk/config');
// Mage::log(json_encode($configSettings), null, 'zendesk.log');
- $this->getResponse()->setHeader('X-Extension-Version', '3.0.0');
+ $this->getResponse()->setHeader('X-Extension-Version', '3.0.1');
return $this;
}
@@ -67,45 +67,39 @@ public function _authorise()
}
$apiToken = Mage::helper('zendesk')->getApiToken(false);
- $provisionToken = Mage::helper('zendesk')->getProvisionToken(false);
-
- // Provisioning tokens are always accepted, hence why they are deleted after the initial process
- if(!$provisionToken || $token != $provisionToken) {
- // Use of the provisioning token "overrides" the configuration for the API, so we check this after
- // confirming the provisioning token has not been sent
- if(!Mage::getStoreConfig('zendesk/api/enabled')) {
- $this->getResponse()
- ->setBody(json_encode(array('success' => false, 'message' => 'API access disabled')))
- ->setHttpResponseCode(403)
- ->setHeader('Content-type', 'application/json', true);
+
+ if(!Mage::getStoreConfig('zendesk/api/enabled')) {
+ $this->getResponse()
+ ->setBody(json_encode(array('success' => false, 'message' => 'API access disabled')))
+ ->setHttpResponseCode(403)
+ ->setHeader('Content-type', 'application/json', true);
- Mage::log('API access disabled.', null, 'zendesk.log');
+ Mage::log('API access disabled.', null, 'zendesk.log');
- return false;
- }
+ return false;
+ }
- // If the API is enabled then check the token
- if(!$token) {
- $this->getResponse()
- ->setBody(json_encode(array('success' => false, 'message' => 'No authorisation token provided')))
- ->setHttpResponseCode(401)
- ->setHeader('Content-type', 'application/json', true);
+ // If the API is enabled then check the token
+ if(!$token) {
+ $this->getResponse()
+ ->setBody(json_encode(array('success' => false, 'message' => 'No authorisation token provided')))
+ ->setHttpResponseCode(401)
+ ->setHeader('Content-type', 'application/json', true);
- Mage::log('No authorisation token provided.', null, 'zendesk.log');
+ Mage::log('No authorisation token provided.', null, 'zendesk.log');
- return false;
- }
+ return false;
+ }
- if($token != $apiToken) {
- $this->getResponse()
- ->setBody(json_encode(array('success' => false, 'message' => 'Not authorised')))
- ->setHttpResponseCode(401)
- ->setHeader('Content-type', 'application/json', true);
+ if($token != $apiToken) {
+ $this->getResponse()
+ ->setBody(json_encode(array('success' => false, 'message' => 'Not authorised')))
+ ->setHttpResponseCode(401)
+ ->setHeader('Content-type', 'application/json', true);
- Mage::log('Not authorised.', null, 'zendesk.log');
+ Mage::log('Not authorised.', null, 'zendesk.log');
- return false;
- }
+ return false;
}
return true;
diff --git a/src/app/code/community/Zendesk/Zendesk/etc/config.xml b/src/app/code/community/Zendesk/Zendesk/etc/config.xml
index 9f1e211e..46437e9f 100644
--- a/src/app/code/community/Zendesk/Zendesk/etc/config.xml
+++ b/src/app/code/community/Zendesk/Zendesk/etc/config.xml
@@ -19,12 +19,9 @@
Learn More at https://agnostack.com/faqs/setup-onboarding/configure-manage-your-account.
Haven't set up Zendesk Support yet? Click below to get started.
]]>