Skip to content

Commit

Permalink
Merge pull request #4 from rafaelpatro/delivery_pattern
Browse files Browse the repository at this point in the history
Improved Delivery Time options
  • Loading branch information
rafaelpatro authored Apr 6, 2017
2 parents da2fed8 + fbc56e6 commit 51aa12e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
15 changes: 11 additions & 4 deletions app/code/community/Quack/GoogleReviews/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Quack_GoogleReviews_Helper_Data extends Mage_Core_Helper_Abstract

const XML_PATH_ESTIMATED_DELIVERY_TIME = 'google/reviews/estimated_delivery_time';

const XML_PATH_ESTIMATED_DELIVERY_PATTERN = 'google/reviews/estimated_delivery_pattern';

/**
* Get Google Merchant account id
*
Expand All @@ -26,6 +28,11 @@ public function getEstimatedDeliveryTime($store = null)
{
return Mage::getStoreConfig(self::XML_PATH_ESTIMATED_DELIVERY_TIME, $store);
}

public function getEstimatedDeliveryPattern($store = null)
{
return Mage::getStoreConfig(self::XML_PATH_ESTIMATED_DELIVERY_PATTERN, $store);
}

/**
*
Expand All @@ -35,14 +42,14 @@ public function getEstimatedDeliveryTime($store = null)
*/
public function getEstimatedDeliveryDate($order)
{
$_pattern = $this->getEstimatedDeliveryTime();
$_time = empty($_pattern) ? 0 : $_pattern;
if ( !is_numeric($_time) ) {
$_time = $this->getEstimatedDeliveryTime();
$_pattern = $this->getEstimatedDeliveryPattern();
if ( !empty($_pattern) ) {
if ( preg_match($_pattern, $order->getShippingDescription(), $matches, PREG_OFFSET_CAPTURE) ) {
$_time = (int)$matches[1][0];
}
$_time = is_numeric($_time) ? $_time : 0;
}
$_time = is_numeric($_time) ? $_time : 0;
$_estimatedDate = new DateTime();
$_estimatedDate->add(new DateInterval("P{$_time}D"));
return $_estimatedDate->format('Y-m-d');
Expand Down
3 changes: 2 additions & 1 deletion app/code/community/Quack/GoogleReviews/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
<reviews>
<active>1</active>
<account>1234567</account>
<estimated_delivery_time>/([0-9]+) days/</estimated_delivery_time>
<estimated_delivery_time>7</estimated_delivery_time>
<estimated_delivery_pattern>/([0-9]+) days/</estimated_delivery_pattern>
<country_code>US</country_code>
</reviews>
</google>
Expand Down
11 changes: 10 additions & 1 deletion app/code/community/Quack/GoogleReviews/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,22 @@
<comment>Your Merchant Center ID. You can get this value from the Google Merchant Center.</comment>
</account>
<estimated_delivery_time translate="label">
<label>Estimated Delivery Time (or pattern)</label>
<label>Estimated Delivery Time</label>
<frontend_type>text</frontend_type>
<sort_order>30</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</estimated_delivery_time>
<estimated_delivery_pattern translate="label">
<label>Estimated Delivery Time (Pattern)</label>
<frontend_type>text</frontend_type>
<sort_order>35</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment>Regular Expression to load the delivery time from shipping description. If no matches is found "Estimated Delivery Time" is applied.</comment>
</estimated_delivery_pattern>
<country_code translate="label">
<label>Country</label>
<frontend_type>text</frontend_type>
Expand Down

0 comments on commit 51aa12e

Please sign in to comment.