Version Notes
new feature : cached shipping rates for faster calculate rates
Download this release
Release Info
| Developer | Ansyori |
| Extension | aongkir |
| Version | 1.2.0.0 |
| Comparing to | |
| See all releases | |
Code changes from version 1.1.0.1 to 1.2.0.0
- app/code/local/Ansyori/Aongkir/Helper/Data.php +131 -1
- app/code/local/Ansyori/Aongkir/Model/Carrier/Ongkir.php +2 -2
- app/code/local/Ansyori/Aongkir/Model/Cron.php +3 -0
- app/code/local/Ansyori/Aongkir/controllers/IndexController.php +5 -0
- app/code/local/Ansyori/Aongkir/etc/system.xml +10 -0
- package.xml +5 -5
app/code/local/Ansyori/Aongkir/Helper/Data.php
CHANGED
|
@@ -30,8 +30,111 @@ class Ansyori_Aongkir_Helper_Data extends Mage_Core_Helper_Abstract
|
|
| 30 |
return $this->config('apiurl');
|
| 31 |
}
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
public function getRates($origin,$dest,$weight,$kurir)
|
| 34 |
{
|
|
|
|
| 35 |
$weight = $weight * 1000;
|
| 36 |
$post_fields = "origin=$origin&destination=$dest&weight=$weight&courier=$kurir";
|
| 37 |
|
|
@@ -58,7 +161,8 @@ class Ansyori_Aongkir_Helper_Data extends Mage_Core_Helper_Abstract
|
|
| 58 |
'text'=> $text.' '.$main_rates['note'],
|
| 59 |
'cost'=> $main_rates['value']
|
| 60 |
);
|
| 61 |
-
|
|
|
|
| 62 |
endforeach;
|
| 63 |
}
|
| 64 |
|
|
@@ -75,6 +179,7 @@ class Ansyori_Aongkir_Helper_Data extends Mage_Core_Helper_Abstract
|
|
| 75 |
|
| 76 |
$curl = curl_init();
|
| 77 |
|
|
|
|
| 78 |
curl_setopt_array($curl, array(
|
| 79 |
CURLOPT_URL => $this->getApiUrl().$method,
|
| 80 |
CURLOPT_RETURNTRANSFER => true,
|
|
@@ -298,5 +403,30 @@ class Ansyori_Aongkir_Helper_Data extends Mage_Core_Helper_Abstract
|
|
| 298 |
return $string;
|
| 299 |
}
|
| 300 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
}
|
| 302 |
|
| 30 |
return $this->config('apiurl');
|
| 31 |
}
|
| 32 |
|
| 33 |
+
public function getActiveCarriers()
|
| 34 |
+
{
|
| 35 |
+
return explode(',',strtolower($this->config('kurir')));
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
public function isDisabledSavedShippingRates()
|
| 39 |
+
{
|
| 40 |
+
return $this->config('disablecached');
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
public function getSavedRates($origin,$dest,$weight,$kurir)
|
| 44 |
+
{
|
| 45 |
+
|
| 46 |
+
if($this->isDisabledSavedShippingRates())
|
| 47 |
+
{
|
| 48 |
+
return $this->getRates($origin,$dest,$weight,$kurir);
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
$array_rates = array();
|
| 52 |
+
$sql = "SELECT distinct dari,ke, harga, kurir, servis,text FROM aongkir_save_rates
|
| 53 |
+
where dari='$origin' and ke='$dest' and kurir='$kurir' ";
|
| 54 |
+
|
| 55 |
+
$sql = $this->fetchSql($sql);
|
| 56 |
+
$count = 0;
|
| 57 |
+
foreach($sql as $datax)
|
| 58 |
+
{
|
| 59 |
+
$count++;
|
| 60 |
+
$array_rates[] = array(
|
| 61 |
+
|
| 62 |
+
'text'=> $datax['text'].' - ',
|
| 63 |
+
'cost'=> $datax['harga'] * $weight
|
| 64 |
+
);
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
if($count)
|
| 68 |
+
{
|
| 69 |
+
return $array_rates;
|
| 70 |
+
}else{
|
| 71 |
+
return $this->getRates($origin,$dest,$weight,$kurir);
|
| 72 |
+
};
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
public function grabAllRates($refreshAll = 0)
|
| 76 |
+
{
|
| 77 |
+
$this->createAdditionalTable();
|
| 78 |
+
$origin = $this->config('origin');
|
| 79 |
+
|
| 80 |
+
if($refreshAll):
|
| 81 |
+
$sql = "delete from aongkir_save_rates";
|
| 82 |
+
|
| 83 |
+
try{
|
| 84 |
+
$this->sql($sql);
|
| 85 |
+
echo 'clear rates sukses'.'<br>';
|
| 86 |
+
}catch(Exception $xx)
|
| 87 |
+
{
|
| 88 |
+
$this->setLog('Erorr Sql : '.$xx->getMessage());
|
| 89 |
+
echo 'clear rates GAGAL'.'<br>';
|
| 90 |
+
};
|
| 91 |
+
endif;
|
| 92 |
+
|
| 93 |
+
$sql = "select distinct city_id from daftar_alamat where city_id not in (select distinct ke from aongkir_save_rates where dari='$origin' order by rand() ) ";
|
| 94 |
+
$sql = $this->fetchSql($sql);
|
| 95 |
+
$kurir_list = $this->getActiveCarriers();
|
| 96 |
+
foreach($sql as $dats)
|
| 97 |
+
{
|
| 98 |
+
foreach($kurir_list as $kurir)
|
| 99 |
+
{
|
| 100 |
+
try{
|
| 101 |
+
$this->getRates($origin,$dats['city_id'],1,$kurir);
|
| 102 |
+
echo 'sukses grab origin : '.$origin.' city id :'.$dats['city_id'].' kurir:'.$kurir.'<br>';
|
| 103 |
+
}catch(Exception $xx)
|
| 104 |
+
{
|
| 105 |
+
$this->setLog('Erorr Sql : '.$xx->getMessage());
|
| 106 |
+
echo 'GAGAL grab origin : '.$origin.' city id :'.$dats['city_id'].' kurir:'.$kurir.'<br>';
|
| 107 |
+
|
| 108 |
+
};
|
| 109 |
+
};
|
| 110 |
+
};
|
| 111 |
+
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
public function saveRate($origin,$dest,$harga,$kurir,$servis,$text)
|
| 115 |
+
{
|
| 116 |
+
if($this->isDisabledSavedShippingRates())
|
| 117 |
+
{
|
| 118 |
+
return true;
|
| 119 |
+
};
|
| 120 |
+
|
| 121 |
+
$this->createAdditionalTable();
|
| 122 |
+
|
| 123 |
+
$sql = "insert into aongkir_save_rates(dari,ke,harga,kurir,servis,text,lup)
|
| 124 |
+
values('$origin','$dest','$harga','$kurir','$servis','$text',now()) ";
|
| 125 |
+
|
| 126 |
+
try{
|
| 127 |
+
$this->sql($sql);
|
| 128 |
+
}catch(Exception $xx)
|
| 129 |
+
{
|
| 130 |
+
$this->setLog('Erorr Sql : '.$xx->getMessage());
|
| 131 |
+
return false;
|
| 132 |
+
};
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
public function getRates($origin,$dest,$weight,$kurir)
|
| 136 |
{
|
| 137 |
+
$ori_weight = $weight;
|
| 138 |
$weight = $weight * 1000;
|
| 139 |
$post_fields = "origin=$origin&destination=$dest&weight=$weight&courier=$kurir";
|
| 140 |
|
| 161 |
'text'=> $text.' '.$main_rates['note'],
|
| 162 |
'cost'=> $main_rates['value']
|
| 163 |
);
|
| 164 |
+
$harga_perkilo = round($main_rates['value']/$ori_weight,0);
|
| 165 |
+
$this->saveRate($origin,$dest,$harga_perkilo,$name_kurir,$listrates['service'],$text);
|
| 166 |
endforeach;
|
| 167 |
}
|
| 168 |
|
| 179 |
|
| 180 |
$curl = curl_init();
|
| 181 |
|
| 182 |
+
|
| 183 |
curl_setopt_array($curl, array(
|
| 184 |
CURLOPT_URL => $this->getApiUrl().$method,
|
| 185 |
CURLOPT_RETURNTRANSFER => true,
|
| 403 |
return $string;
|
| 404 |
}
|
| 405 |
|
| 406 |
+
public function createAdditionalTable()
|
| 407 |
+
{
|
| 408 |
+
$sql = '
|
| 409 |
+
CREATE TABLE IF NOT EXISTS `aongkir_save_rates` (
|
| 410 |
+
`idx` int(6) unsigned NOT NULL AUTO_INCREMENT,
|
| 411 |
+
`dari` varchar(255) NOT NULL,
|
| 412 |
+
`ke` varchar(30) NOT NULL,
|
| 413 |
+
`harga` decimal(19,4) DEFAULT NULL,
|
| 414 |
+
`lup` datetime DEFAULT NULL,
|
| 415 |
+
`kurir` varchar(255) NOT NULL,
|
| 416 |
+
`servis` varchar(255) NOT NULL,
|
| 417 |
+
`text` text NOT NULL,
|
| 418 |
+
PRIMARY KEY (`idx`)
|
| 419 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
| 420 |
+
';
|
| 421 |
+
try{
|
| 422 |
+
$this->sql($sql);
|
| 423 |
+
|
| 424 |
+
}catch(Exception $xx)
|
| 425 |
+
{
|
| 426 |
+
$this->setLog('Erorr Sql : '.$xx->getMessage());
|
| 427 |
+
return false;
|
| 428 |
+
}
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
}
|
| 432 |
|
app/code/local/Ansyori/Aongkir/Model/Carrier/Ongkir.php
CHANGED
|
@@ -65,9 +65,9 @@ class Ansyori_Aongkir_Model_Carrier_Ongkir
|
|
| 65 |
foreach($carriers as $kurir)
|
| 66 |
{
|
| 67 |
if($weight > 29){
|
| 68 |
-
$rates_by_kurir = $this->helper()->
|
| 69 |
}else{
|
| 70 |
-
$rates_by_kurir = $this->helper()->
|
| 71 |
};
|
| 72 |
foreach($rates_by_kurir as $final_list)
|
| 73 |
{
|
| 65 |
foreach($carriers as $kurir)
|
| 66 |
{
|
| 67 |
if($weight > 29){
|
| 68 |
+
$rates_by_kurir = $this->helper()->getSavedRates($origin,$dest,1,$kurir);
|
| 69 |
}else{
|
| 70 |
+
$rates_by_kurir = $this->helper()->getSavedRates($origin,$dest,$weight,$kurir);
|
| 71 |
};
|
| 72 |
foreach($rates_by_kurir as $final_list)
|
| 73 |
{
|
app/code/local/Ansyori/Aongkir/Model/Cron.php
CHANGED
|
@@ -9,5 +9,8 @@
|
|
| 9 |
class Ansyori_Aongkir_Model_Cron{
|
| 10 |
public function UpdateAlamat(){
|
| 11 |
//do something
|
|
|
|
|
|
|
|
|
|
| 12 |
}
|
| 13 |
}
|
| 9 |
class Ansyori_Aongkir_Model_Cron{
|
| 10 |
public function UpdateAlamat(){
|
| 11 |
//do something
|
| 12 |
+
$helper = Mage::helper('aongkir')->grabAllRates(1);
|
| 13 |
+
$helper = Mage::helper('aongkir')->saveAreaToDb();
|
| 14 |
+
|
| 15 |
}
|
| 16 |
}
|
app/code/local/Ansyori/Aongkir/controllers/IndexController.php
CHANGED
|
@@ -91,4 +91,9 @@ class Ansyori_Aongkir_IndexController extends Mage_Core_Controller_Front_Action{
|
|
| 91 |
{
|
| 92 |
return Mage::helper($type);
|
| 93 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
}
|
| 91 |
{
|
| 92 |
return Mage::helper($type);
|
| 93 |
}
|
| 94 |
+
|
| 95 |
+
public function refreshratesAction()
|
| 96 |
+
{
|
| 97 |
+
$this->helper()->grabAllRates();
|
| 98 |
+
}
|
| 99 |
}
|
app/code/local/Ansyori/Aongkir/etc/system.xml
CHANGED
|
@@ -176,6 +176,16 @@
|
|
| 176 |
<show_in_store>1</show_in_store>
|
| 177 |
<comment><![CDATA[example: +5% , +5000 , -5% , -5000 , leave it empty if not necessary, plus(+) or minus (-) sign is MANDATORY to use this feature ]]></comment>
|
| 178 |
</changeprice>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
|
| 181 |
</fields>
|
| 176 |
<show_in_store>1</show_in_store>
|
| 177 |
<comment><![CDATA[example: +5% , +5000 , -5% , -5000 , leave it empty if not necessary, plus(+) or minus (-) sign is MANDATORY to use this feature ]]></comment>
|
| 178 |
</changeprice>
|
| 179 |
+
|
| 180 |
+
<disablecached translate="label">
|
| 181 |
+
<label>Disabled cached shipping rates</label>
|
| 182 |
+
<frontend_type>select</frontend_type>
|
| 183 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 184 |
+
<sort_order>9999</sort_order>
|
| 185 |
+
<show_in_default>1</show_in_default>
|
| 186 |
+
<show_in_website>1</show_in_website>
|
| 187 |
+
<show_in_store>1</show_in_store>
|
| 188 |
+
</disablecached>
|
| 189 |
|
| 190 |
|
| 191 |
</fields>
|
package.xml
CHANGED
|
@@ -1,18 +1,18 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>aongkir</name>
|
| 4 |
-
<version>1.
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license>open source</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
<summary>Indonesian Shippping Carriers</summary>
|
| 10 |
<description>Indonesian Shippping Carriers</description>
|
| 11 |
-
<notes>
|
| 12 |
<authors><author><name>Ansyori</name><user>ansyori</user><email>ansyori@gmail.com</email></author></authors>
|
| 13 |
-
<date>2015-06
|
| 14 |
-
<time>03:
|
| 15 |
-
<contents><target name="magelocal"><dir name="Ansyori"><dir name="Aongkir"><dir name="Block"><file name="Index.php" hash="eb68794e0f3220839a02dba0f9f7f105"/></dir><dir name="Helper"><file name="Data.php" hash="
|
| 16 |
<compatible/>
|
| 17 |
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
| 18 |
</package>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>aongkir</name>
|
| 4 |
+
<version>1.2.0.0</version>
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license>open source</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
<summary>Indonesian Shippping Carriers</summary>
|
| 10 |
<description>Indonesian Shippping Carriers</description>
|
| 11 |
+
<notes>new feature : cached shipping rates for faster calculate rates</notes>
|
| 12 |
<authors><author><name>Ansyori</name><user>ansyori</user><email>ansyori@gmail.com</email></author></authors>
|
| 13 |
+
<date>2015-08-06</date>
|
| 14 |
+
<time>03:14:09</time>
|
| 15 |
+
<contents><target name="magelocal"><dir name="Ansyori"><dir name="Aongkir"><dir name="Block"><file name="Index.php" hash="eb68794e0f3220839a02dba0f9f7f105"/></dir><dir name="Helper"><file name="Data.php" hash="dfa0ef6afd679b48be587fe7e976299c"/></dir><dir name="Model"><file name="Area.php" hash="a50294a1ead04ef920bd79c457f4bc8a"/><dir name="Carrier"><file name="Ongkir.php" hash="b21ff335715653c4d52aaa75d3d4a47b"/></dir><file name="Cron.php" hash="e9201b850d3593cb04119ae1bc6fd4c5"/><dir name="Mysql4"><dir name="Area"><file name="Collection.php" hash="5a1d6cfd02be80f7038f3cafd27f3ec1"/></dir><file name="Area.php" hash="79392c31d15280d608e47a12bcda6685"/></dir><dir name="System"><dir name="Config"><dir name="Source"><file name="City.php" hash="db48d237dd037433d142e7bfd4fbe15a"/><file name="Kurir.php" hash="6b42824b026a709f56faa600e6cf1428"/></dir></dir></dir></dir><dir name="controllers"><file name="IndexController.php" hash="3d98973319858c0bd9dc6e4bb4b01638"/></dir><dir name="etc"><file name="adminhtml.xml" hash="7524c909e4c0ac821d4e0d41379c04d2"/><file name="config.xml" hash="ad9e0216ad24f345651bb8be9b096d42"/><file name="system.xml" hash="0b0f30f2368136be63293917d7079070"/></dir><dir name="sql"><dir name="aongkir_setup"><file name="mysql4-install-1.0.0.php" hash="4e8ba5ec0e19a30d13bb9568be4605eb"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="aongkir.xml" hash="ec81d1456c144f706915d4daa6fb14d0"/></dir><dir name="template"><dir name="aongkir"><file name="billing.phtml" hash="3ff4e7d9d8043373bae8700e8c14c467"/><file name="edit.phtml" hash="59d5befe7677f4fad38a92f8a4764074"/><file name="shipping.phtml" hash="c18bcbe1da77b90de0a11efa9138e895"/></dir></dir></dir></dir><dir name="rwd"><dir name="default"><dir name="layout"><file name="aongkir.xml" hash="ec81d1456c144f706915d4daa6fb14d0"/></dir><dir name="template"><dir name="aongkir"><file name="billing.phtml" hash="dac284ef3d6a94bd9775f4e1b8510387"/><file name="edit.phtml" hash="59d5befe7677f4fad38a92f8a4764074"/><file name="shipping.phtml" hash="3434b8c160cd22bbe1a45a5cc6689f41"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ansyori_Aongkir.xml" hash="f7f4be17fe16141cff15994c4f202a0f"/></dir></target></contents>
|
| 16 |
<compatible/>
|
| 17 |
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
| 18 |
</package>
|
