Skip to content

Commit f213e09

Browse files
authored
Merge pull request #178 from agnostack/master
Release 3.0.1 > develop
2 parents 307a58e + d27c4f9 commit f213e09

File tree

8 files changed

+105
-185
lines changed

8 files changed

+105
-185
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The new 3.0 version fixes several core issues (incorrect/missing order address,
88
* Enable direct Order Search by ID
99
* Access Order Messages and Notes
1010

11-
Dowload the latest version of the extension at: https://github.com./agnostack/magento_extension/releases/tag/v3.0.0.
11+
Dowload the latest version of the extension at: https://github.com./agnostack/magento_extension/releases/tag/v3.0.1.
1212

1313
Additional detailed instructions on configuring agnoStack for the new version can be found at: https://agnostack.com/faqs/setup-onboarding/configuring-magento-1.
1414

src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Config/Buttons/Signup.php

+1-38
Original file line numberDiff line numberDiff line change
@@ -37,48 +37,11 @@ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
3737
$originalData = $element->getOriginalData();
3838
$this->addData(array(
3939
'button_label' => Mage::helper('zendesk')->__($originalData['button_label']),
40+
'button_url' => Mage::helper('zendesk')->__($originalData['button_url']),
4041
'html_id' => $element->getHtmlId(),
4142
'url' => Mage::getSingleton('adminhtml/url')->getUrl('*/setup/start')
4243
));
4344

4445
return $this->_toHtml();
4546
}
46-
47-
public function getPostUrl()
48-
{
49-
return Mage::helper('zendesk')->getProvisionUrl();
50-
}
51-
52-
public function getPostInfo()
53-
{
54-
$websiteCode = Mage::app()->getRequest()->getParam('website');
55-
if ($websiteCode) {
56-
$website = Mage::getModel('core/website')->load($websiteCode);
57-
} else {
58-
$website = Mage::getModel('core/website')->getCollection()
59-
->addFieldToFilter('is_default', 1)
60-
->getFirstItem();
61-
}
62-
63-
$storeCode = Mage::app()->getRequest()->getParam('store');
64-
if ($storeCode) {
65-
$store = Mage::getModel('core/store')->load($storeCode);
66-
} else {
67-
$store = $website->getDefaultStore();
68-
}
69-
70-
$info = array(
71-
'magento_domain' => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB),
72-
'magento_current_user_id' => Mage::getSingleton('admin/session')->getUser()->getUserId(),
73-
'magento_user_count' => Mage::getModel('admin/user')->getCollection()->getSize(),
74-
'magento_auth_token' => Mage::helper('zendesk')->getProvisionToken(true),
75-
'magento_callback' => Mage::helper('adminhtml')->getUrl('adminhtml/zendesk/redirect', array('type' => 'settings', 'id' => 'zendesk')),
76-
'magento_locale' => Mage::getStoreConfig('general/locale/code'),
77-
'magento_timezone' => Mage::getStoreConfig('general/locale/timezone'),
78-
'magento_api_url' => Mage::getUrl('zendesk/api', array('_store' => $store->getCode())),
79-
'magento_store_name' => $website->getName(),
80-
);
81-
82-
return $info;
83-
}
8447
}

src/app/code/community/Zendesk/Zendesk/Helper/Data.php

+71-96
Original file line numberDiff line numberDiff line change
@@ -154,46 +154,6 @@ public function setApiToken($token = null)
154154
return $token;
155155
}
156156

157-
/**
158-
* Returns the provisioning endpoint for new setups.
159-
*
160-
* This uses the config/zendesk/provision_url XML path to retrieve the setting, with a default value set in
161-
* the extension config.xml file. This can be overridden in your website's local.xml file.
162-
* @return null|string URL or null on failure
163-
*/
164-
public function getProvisionUrl()
165-
{
166-
$config = Mage::getConfig();
167-
$data = $config->getNode('zendesk/provision_url');
168-
if(!$data) {
169-
return null;
170-
}
171-
return (string)$data;
172-
}
173-
174-
public function getProvisionToken($generate = false)
175-
{
176-
$token = Mage::getStoreConfig('zendesk/hidden/provision_token', 0);
177-
178-
if( (!$token || strlen(trim($token)) == 0) && $generate) {
179-
$token = $this->setProvisionToken();
180-
}
181-
182-
return $token;
183-
}
184-
185-
public function setProvisionToken($token = null)
186-
{
187-
if(!$token) {
188-
$token = hash('sha256', Mage::helper('oauth')->generateToken());
189-
}
190-
191-
Mage::getModel('core/config')->saveConfig('zendesk/hidden/provision_token', $token, 'default');
192-
Mage::getConfig()->removeCache();
193-
194-
return $token;
195-
}
196-
197157
public function getOrderDetail($order)
198158
{
199159
// if the admin site has a custom URL, use it
@@ -479,24 +439,26 @@ protected function formatCustomer($order)
479439

480440
protected function formatAddress($address)
481441
{
482-
$addressData = array(
483-
'type' => 'address',
484-
'first_name' => $address->getFirstname(),
485-
'last_name' => $address->getLastname(),
486-
'city' => $address->getCity(),
487-
'county' => $address->getRegion(),
488-
'postcode' => $address->getPostcode(),
489-
'country' => $address->getCountryId(),
490-
'phone' => $address->getTelephone()
491-
);
492-
493-
$entityId = $address->getEntityId();
494-
$addressId = $address->getCustomerAddressId();
495-
$addressData['id'] = $addressId ?: $entityId;
496-
497-
$street = $address->getStreet();
498-
$addressData['line_1'] = $street[0] ?: '';
499-
$addressData['line_2'] = $street[1] ?: '';
442+
if ($address) {
443+
$addressData = array(
444+
'type' => 'address',
445+
'first_name' => $address->getFirstname(),
446+
'last_name' => $address->getLastname(),
447+
'city' => $address->getCity(),
448+
'county' => $address->getRegion(),
449+
'postcode' => $address->getPostcode(),
450+
'country' => $address->getCountryId(),
451+
'phone' => $address->getTelephone()
452+
);
453+
454+
$entityId = $address->getEntityId();
455+
$addressId = $address->getCustomerAddressId();
456+
$addressData['id'] = $addressId ?: $entityId;
457+
458+
$street = $address->getStreet();
459+
$addressData['line_1'] = $street[0] ?: '';
460+
$addressData['line_2'] = $street[1] ?: '';
461+
}
500462

501463
return $addressData;
502464
}
@@ -505,44 +467,52 @@ public function getShipments($order)
505467
{
506468
$shipments = array();
507469
$orderStatus = $order->getStatus();
470+
$serviceCode = $order->getShippingDescription();
471+
$tracks = $order->getTracksCollection();
472+
$shippingMethod = $order->getShippingMethod();
473+
$orderShippingAddress = $order->getShippingAddress();
508474

509475
foreach($order->getShipmentsCollection() as $shipment) {
510476
$shipmentId = $shipment->getEntityId();
511477
$shippingAddress = $shipment->getShippingAddress();
512-
$serviceCode = $order->getShippingDescription();
513-
}
514-
515-
if ($shipmentId) {
516-
$tracks = $order->getTracksCollection();
517-
if (count($tracks) > 0) {
518-
foreach($tracks as $track) {
519-
if ($shipmentId == $track->getParentId()) {
520-
$shipments[] = array(
521-
'id' => $track->getEntityId(),
522-
'carrier' => $track->getTitle(),
523-
'carrier_code' => $track->getCarrierCode(),
524-
'service_code' => $serviceCode,
525-
'shipping_description' => $track->getDescription() ?: '',
526-
'created_at' => $track->getCreatedAt(),
527-
'updated_at' => $track->getUpdatedAt(),
528-
'tracking_number' => $track->getTrackNumber(),
529-
'shipping_address' => $this->formatAddress($shippingAddress),
530-
'order_status' => $orderStatus,
531-
);
478+
if ($shipmentId) {
479+
if (count($tracks) > 0) {
480+
foreach($tracks as $track) {
481+
if ($shipmentId == $track->getParentId()) {
482+
$shipment = array(
483+
'id' => $track->getEntityId(),
484+
'carrier' => $track->getTitle(),
485+
'carrier_code' => $track->getCarrierCode(),
486+
'service_code' => $serviceCode,
487+
'shipping_description' => $track->getDescription() ?: '',
488+
'created_at' => $track->getCreatedAt(),
489+
'updated_at' => $track->getUpdatedAt(),
490+
'tracking_number' => $track->getTrackNumber(),
491+
'order_status' => $orderStatus,
492+
);
493+
if ($shippingAddress) {
494+
$shipment['shipping_address'] = $this->formatAddress($shippingAddress);
495+
}
496+
$shipments[] = $shipment;
497+
}
498+
}
499+
} else {
500+
$shipment = array(
501+
'service_code' => $serviceCode,
502+
'carrier_code' => $shippingMethod,
503+
'order_status' => $orderStatus,
504+
);
505+
if ($shippingAddress) {
506+
$shipment['shipping_address'] = $this->formatAddress($shippingAddress);
532507
}
508+
$shipments[] = $shipment;
533509
}
534-
} else {
535-
$shipments[] = array(
536-
'service_code' => $serviceCode,
537-
'carrier_code' => $order->getShippingMethod(),
538-
'shipping_address' => $this->formatAddress($shippingAddress),
539-
'order_status' => $orderStatus,
540-
);
541510
}
542-
} else {
543-
$shippingAddress = $order->getShippingAddress();
511+
}
512+
513+
if (empty($shipments) && $orderShippingAddress) {
544514
$shipments[] = array(
545-
'shipping_address' => $this->formatAddress($shippingAddress),
515+
'shipping_address' => $this->formatAddress($orderShippingAddress),
546516
);
547517
}
548518

@@ -558,22 +528,22 @@ public function getOrderDetailBasic($order)
558528
$shippingAddress = $order->getShippingAddress();
559529
$shippingWithTax = $order->getShippingInclTax();
560530
$shippingMethod = $order->getShippingMethod();
531+
$billingAddress = $order->getBillingAddress();
561532

562533
$orderInfo = array(
563534
'id' => $order->getIncrementId(),
564535
'url' => $urlModel->getUrl('adminhtml/sales_order/view', array('order_id' => $order->getId())),
565536
'transaction_id' => $order->getIncrementId(),
566537
'status' => $order->getStatus(),
567-
'billing_address' => $this->formatAddress($order->getBillingAddress()),
568538
'meta' => array(
569539
'store_info' => array(
570540
'type' => 'store_info',
571541
'name' => $order->getStoreName()
572542
),
573543
'display_price' => array(
574544
'with_tax' => $this->formatPrice($order->getGrandTotal(), $currency),
575-
'without_tax' => $this->formatPrice($order->getGrandTotal() - $order->getTaxAmount(), $currency), // TODO: get without tax
576-
'tax' => $this->formatPrice($order->getTaxAmount(), $currency) // TODO: get tax
545+
'without_tax' => $this->formatPrice($order->getGrandTotal() - $order->getTaxAmount(), $currency),
546+
'tax' => $this->formatPrice($order->getTaxAmount(), $currency)
577547
),
578548
'timestamps' => array(
579549
'created_at' => $order->getCreatedAt(),
@@ -590,9 +560,12 @@ public function getOrderDetailBasic($order)
590560
),
591561
'shipments' => array(),
592562
);
563+
if ($billingAddress) {
564+
$orderInfo['billing_address'] = $this->formatAddress($billingAddress);
565+
}
593566

594567
foreach($order->getItemsCollection(array(), true) as $item) {
595-
$itemWithTax = $item->getRowTotal();
568+
$itemWithoutTax = $item->getRowTotal();
596569
$itemTax = $item->getTaxAmount();
597570

598571
$productId = $item->getProductId();
@@ -610,8 +583,8 @@ public function getOrderDetailBasic($order)
610583
'refunded' => intval($item->getQtyRefunded()),
611584
'meta' => array(
612585
'display_price' => array(
613-
'with_tax' => $this->formatPrice($itemWithTax, $currency),
614-
'without_tax' => $this->formatPrice($itemWithTax - $itemTax, $currency),
586+
'with_tax' => $this->formatPrice($itemWithoutTax + $itemTax, $currency),
587+
'without_tax' => $this->formatPrice($itemWithoutTax, $currency),
615588
'tax' => $this->formatPrice($iitemTax, $currency)
616589
),
617590
'timestamps' => array(
@@ -772,7 +745,9 @@ public function getCustomer($customer)
772745
);
773746

774747
foreach($customer->getAddressesCollection() as $address) {
775-
$info['addresses'][] = $this->formatAddress($address);
748+
if ($address) {
749+
$info['addresses'][] = $this->formatAddress($address);
750+
}
776751
}
777752

778753
return $info;
@@ -825,7 +800,7 @@ public function getFilteredOrdersByProduct($customerFilters, $productFilters)
825800
);
826801
}
827802

828-
if($email) {
803+
if ($email) {
829804
$filteredOrdersData = array_filter(array_values($ordersData), function ($orderData) use ($email) {
830805
return ($orderData['email'] == $email);
831806
});

src/app/code/community/Zendesk/Zendesk/controllers/ApiController.php

+26-32
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function preDispatch() {
2323
// TODO!!!!!!!: read version from config.xml
2424
// $configSettings = Mage::getSingleton('Zendesk_Zendesk/config');
2525
// Mage::log(json_encode($configSettings), null, 'zendesk.log');
26-
$this->getResponse()->setHeader('X-Extension-Version', '3.0.0');
26+
$this->getResponse()->setHeader('X-Extension-Version', '3.0.1');
2727
return $this;
2828
}
2929

@@ -67,45 +67,39 @@ public function _authorise()
6767
}
6868

6969
$apiToken = Mage::helper('zendesk')->getApiToken(false);
70-
$provisionToken = Mage::helper('zendesk')->getProvisionToken(false);
71-
72-
// Provisioning tokens are always accepted, hence why they are deleted after the initial process
73-
if(!$provisionToken || $token != $provisionToken) {
74-
// Use of the provisioning token "overrides" the configuration for the API, so we check this after
75-
// confirming the provisioning token has not been sent
76-
if(!Mage::getStoreConfig('zendesk/api/enabled')) {
77-
$this->getResponse()
78-
->setBody(json_encode(array('success' => false, 'message' => 'API access disabled')))
79-
->setHttpResponseCode(403)
80-
->setHeader('Content-type', 'application/json', true);
70+
71+
if(!Mage::getStoreConfig('zendesk/api/enabled')) {
72+
$this->getResponse()
73+
->setBody(json_encode(array('success' => false, 'message' => 'API access disabled')))
74+
->setHttpResponseCode(403)
75+
->setHeader('Content-type', 'application/json', true);
8176

82-
Mage::log('API access disabled.', null, 'zendesk.log');
77+
Mage::log('API access disabled.', null, 'zendesk.log');
8378

84-
return false;
85-
}
79+
return false;
80+
}
8681

87-
// If the API is enabled then check the token
88-
if(!$token) {
89-
$this->getResponse()
90-
->setBody(json_encode(array('success' => false, 'message' => 'No authorisation token provided')))
91-
->setHttpResponseCode(401)
92-
->setHeader('Content-type', 'application/json', true);
82+
// If the API is enabled then check the token
83+
if(!$token) {
84+
$this->getResponse()
85+
->setBody(json_encode(array('success' => false, 'message' => 'No authorisation token provided')))
86+
->setHttpResponseCode(401)
87+
->setHeader('Content-type', 'application/json', true);
9388

94-
Mage::log('No authorisation token provided.', null, 'zendesk.log');
89+
Mage::log('No authorisation token provided.', null, 'zendesk.log');
9590

96-
return false;
97-
}
91+
return false;
92+
}
9893

99-
if($token != $apiToken) {
100-
$this->getResponse()
101-
->setBody(json_encode(array('success' => false, 'message' => 'Not authorised')))
102-
->setHttpResponseCode(401)
103-
->setHeader('Content-type', 'application/json', true);
94+
if($token != $apiToken) {
95+
$this->getResponse()
96+
->setBody(json_encode(array('success' => false, 'message' => 'Not authorised')))
97+
->setHttpResponseCode(401)
98+
->setHeader('Content-type', 'application/json', true);
10499

105-
Mage::log('Not authorised.', null, 'zendesk.log');
100+
Mage::log('Not authorised.', null, 'zendesk.log');
106101

107-
return false;
108-
}
102+
return false;
109103
}
110104

111105
return true;

src/app/code/community/Zendesk/Zendesk/etc/config.xml

+1-4
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@
1919
<config>
2020
<modules>
2121
<Zendesk_Zendesk>
22-
<version>3.0.0</version>
22+
<version>3.0.1</version>
2323
</Zendesk_Zendesk>
2424
</modules>
25-
<zendesk>
26-
<provision_url>https://signup.zendesk.com/provisioning/magento/welcome</provision_url>
27-
</zendesk>
2825
<global>
2926
<models>
3027
<zendesk>

0 commit comments

Comments
 (0)