Version Notes
Formatting updated
Download this release
Release Info
| Developer | Magento Core Team |
| Extension | RetentionScience_Waves |
| Version | 2.1.8 |
| Comparing to | |
| See all releases | |
Code changes from version 2.1.7 to 2.1.8
- app/code/community/RetentionScience/Waves/Block/Adminhtml/Syncbutton.php +0 -1
- app/code/community/RetentionScience/Waves/Block/Waves.php +0 -1
- app/code/community/RetentionScience/Waves/Model/Observer.php +407 -440
- app/code/community/RetentionScience/Waves/Model/Source/Categorytree.php +1 -16
- app/code/community/RetentionScience/Waves/Model/Source/Cronconfig.php +24 -26
- app/code/community/RetentionScience/Waves/Model/Source/Rscoredata.php +0 -1
- app/code/community/RetentionScience/Waves/Model/retention_science_api.php +176 -176
- app/code/community/RetentionScience/Waves/Model/rs_get_save_config.php +15 -16
- app/code/community/RetentionScience/Waves/Model/rs_send_categories.php +16 -17
- app/code/community/RetentionScience/Waves/Model/rs_send_orders.php +10 -16
- app/code/community/RetentionScience/Waves/Model/rs_send_products.php +10 -18
- app/code/community/RetentionScience/Waves/Model/rs_send_users.php +11 -18
- app/code/community/RetentionScience/Waves/Model/rs_sync_data.php +115 -114
- app/code/community/RetentionScience/Waves/controllers/AdminController.php +10 -10
- app/code/community/RetentionScience/Waves/controllers/IndexController.php +24 -24
- app/code/community/RetentionScience/Waves/etc/config.xml +1 -2
- app/code/community/RetentionScience/Waves/etc/system.xml +0 -10
- app/design/frontend/base/default/template/waves/waves.phtml +8 -8
- js/RetentionScience/retention_science_wave.js +25 -26
- package.xml +5 -5
app/code/community/RetentionScience/Waves/Block/Adminhtml/Syncbutton.php
CHANGED
|
@@ -22,7 +22,6 @@ class RetentionScience_Waves_Block_Adminhtml_Syncbutton
|
|
| 22 |
->setType('button')
|
| 23 |
->setClass('run_now_button')
|
| 24 |
->setLabel($title)
|
| 25 |
-
//$this->__('Add')
|
| 26 |
->setOnClick("location.href='$link_url';")
|
| 27 |
->setDisabled(false)
|
| 28 |
->toHtml();
|
| 22 |
->setType('button')
|
| 23 |
->setClass('run_now_button')
|
| 24 |
->setLabel($title)
|
|
|
|
| 25 |
->setOnClick("location.href='$link_url';")
|
| 26 |
->setDisabled(false)
|
| 27 |
->toHtml();
|
app/code/community/RetentionScience/Waves/Block/Waves.php
CHANGED
|
@@ -58,7 +58,6 @@ class RetentionScience_Waves_Block_Waves extends Mage_Core_Block_Template
|
|
| 58 |
return Mage::getStoreConfig('waves/retentionscience_settings/ajaxaddtocartenable');
|
| 59 |
}
|
| 60 |
public function customerId(){
|
| 61 |
-
//$customerId = Mage::getSingleton('customer/session')->getCustomerId();
|
| 62 |
$email = Mage::getSingleton('customer/session')->getCustomer()->getEmail();
|
| 63 |
$user_record_id = md5(trim(strtolower($email)));
|
| 64 |
return $user_record_id;
|
| 58 |
return Mage::getStoreConfig('waves/retentionscience_settings/ajaxaddtocartenable');
|
| 59 |
}
|
| 60 |
public function customerId(){
|
|
|
|
| 61 |
$email = Mage::getSingleton('customer/session')->getCustomer()->getEmail();
|
| 62 |
$user_record_id = md5(trim(strtolower($email)));
|
| 63 |
return $user_record_id;
|
app/code/community/RetentionScience/Waves/Model/Observer.php
CHANGED
|
@@ -1,487 +1,454 @@
|
|
| 1 |
<?php
|
| 2 |
-
// ini_set('display_errors', '1');
|
| 3 |
include('retention_science_api.php');
|
| 4 |
$last_processed_order_record_id;
|
| 5 |
$last_processed_user_entity_id;
|
| 6 |
$last_processed_product_entity_id;
|
| 7 |
|
|
|
|
|
|
|
| 8 |
class RetentionScience_Waves_Model_Observer
|
| 9 |
{
|
| 10 |
-
|
| 11 |
-
protected $phpBin = 'php'; // only used if useExec==true
|
| 12 |
-
// can use sendBulkUpload with or without useExec
|
| 13 |
-
// or can just use API by setting sendBulkUpload=false
|
| 14 |
protected $sendBulkUpload = true;
|
| 15 |
-
protected $useBulkCompression = true;
|
| 16 |
-
protected $useExec = false;
|
| 17 |
protected $removeFileAfterSend = true; // only used if sendBulkUpload==true
|
| 18 |
protected $logToFile = false;
|
| 19 |
protected $elementsPerPage = 2000;
|
| 20 |
protected $apiClient;
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
public function getPhpBin(){
|
| 34 |
-
$php_bin = Mage::getStoreConfig('waves/rs_sync_advanced/rs_php_bin');
|
| 35 |
-
if ($php_bin == NULL){
|
| 36 |
-
$php_bin = $this->phpBin;
|
| 37 |
-
}
|
| 38 |
-
// echo "PHP_BIN is [ $php_bin ] \n";
|
| 39 |
-
return $php_bin;
|
| 40 |
-
}
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
$send_bulk_upload = $this->sendBulkUpload;
|
| 50 |
-
}
|
| 51 |
-
// echo "send_bulk_upload is [ $send_bulk_upload ] \n";
|
| 52 |
-
return $send_bulk_upload;
|
| 53 |
-
}
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
$use_exec = $this->useExec;
|
| 71 |
-
}
|
| 72 |
-
//echo "use_exec is [ $use_exec ] \n";
|
| 73 |
-
return $use_exec;
|
| 74 |
-
}
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
}
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
|
| 126 |
-
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
| 130 |
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
|
| 138 |
-
|
| 139 |
|
| 140 |
-
|
| 141 |
|
| 142 |
-
|
| 143 |
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
$model = $product->getSku();
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
$item_url = $product->getProductUrl();
|
| 168 |
-
// $item_url = Mage::helper('catalog/product')->getProductUrl($product_id);
|
| 169 |
-
// $item_url = $product->getUrlPath();
|
| 170 |
-
//$_category = Mage::getModel('catalog/category')->load($categories[0]);
|
| 171 |
-
//$item_url = Mage::getUrl($_category->getUrlPath()).basename($product->getProductUrl());
|
| 172 |
-
//$item_url = $product->getUrlInStore();
|
| 173 |
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
|
| 215 |
-
|
| 216 |
-
|
| 217 |
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
|
| 242 |
-
|
| 243 |
-
|
| 244 |
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
}
|
| 315 |
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
// save memory
|
| 350 |
-
// $product->clearInstance(); // doesnt work on older magento installs
|
| 351 |
-
unset($product);
|
| 352 |
-
}
|
| 353 |
-
// Save memory ?
|
| 354 |
-
unset($orderAllItems);
|
| 355 |
-
|
| 356 |
-
$user_record_id = md5(trim(strtolower($order->getCustomerEmail())));
|
| 357 |
-
if($order->getCustomerIsGuest()){
|
| 358 |
-
$email = $order->getCustomerEmail();
|
| 359 |
-
$user_record_id = md5(trim(strtolower($email)));
|
| 360 |
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
|
|
|
| 364 |
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
$regionModel = Mage::getModel('directory/region')->load($address->getRegionId());
|
| 369 |
-
$region = $regionModel->getName();
|
| 370 |
-
$zip = $address->getPostcode();
|
| 371 |
-
$country = $address->getCountryId();
|
| 372 |
-
$phone = $address->getTelephone();
|
| 373 |
-
$accountCreatedAt = $order->getCreatedAt();
|
| 374 |
-
$accountUpdatedAt = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(strtotime($accountCreatedAt)));
|
| 375 |
-
$accountCreatedAt = date("Y-m-d", Mage::getModel('core/date')->timestamp(strtotime($accountCreatedAt)));
|
| 376 |
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 382 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 383 |
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
//echo "after: " . memory_get_usage() . "\n";
|
| 482 |
-
}
|
| 483 |
|
| 484 |
-
|
| 485 |
{
|
| 486 |
if (Mage::app()->getFrontController()->getAction()->getFullActionName() === 'adminhtml_dashboard_index')
|
| 487 |
{
|
|
@@ -516,21 +483,21 @@ class RetentionScience_Waves_Model_Observer
|
|
| 516 |
return $rscore_json;
|
| 517 |
}
|
| 518 |
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
|
| 524 |
-
|
| 525 |
-
|
| 526 |
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
}
|
| 1 |
<?php
|
|
|
|
| 2 |
include('retention_science_api.php');
|
| 3 |
$last_processed_order_record_id;
|
| 4 |
$last_processed_user_entity_id;
|
| 5 |
$last_processed_product_entity_id;
|
| 6 |
|
| 7 |
+
// if sendBulkUpload, do not access the RS API for individual records, instead just ouput all entities to a file
|
| 8 |
+
|
| 9 |
class RetentionScience_Waves_Model_Observer
|
| 10 |
{
|
| 11 |
+
protected $phpBin = 'php';
|
|
|
|
|
|
|
|
|
|
| 12 |
protected $sendBulkUpload = true;
|
| 13 |
+
protected $useBulkCompression = true; // only used if sendBulkUpload==true
|
|
|
|
| 14 |
protected $removeFileAfterSend = true; // only used if sendBulkUpload==true
|
| 15 |
protected $logToFile = false;
|
| 16 |
protected $elementsPerPage = 2000;
|
| 17 |
protected $apiClient;
|
| 18 |
|
| 19 |
+
public function getRetentionScienceApiClient(){
|
| 20 |
+
if(!$this->apiClient){
|
| 21 |
+
$api_user = Mage::getStoreConfig('waves/retentionscience_settings/api_user');
|
| 22 |
+
$api_pass = Mage::getStoreConfig('waves/retentionscience_settings/api_pass');
|
| 23 |
+
$testmode = Mage::getStoreConfig('waves/retentionscience_settings/testmode');
|
| 24 |
+
$this->apiClient = new RetentionScienceApi($api_user, $api_pass, $testmode);
|
| 25 |
+
}
|
| 26 |
+
return $this->apiClient;
|
| 27 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
public function getPhpBin(){
|
| 30 |
+
$php_bin = Mage::getStoreConfig('waves/rs_sync_advanced/rs_php_bin');
|
| 31 |
+
if ($php_bin == NULL){
|
| 32 |
+
$php_bin = $this->phpBin;
|
| 33 |
+
}
|
| 34 |
+
return $php_bin;
|
| 35 |
+
}
|
| 36 |
|
| 37 |
+
public function logToFile(){
|
| 38 |
+
return $this->logToFile;
|
| 39 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
public function sendBulkUpload(){
|
| 42 |
+
$send_bulk_upload = Mage::getStoreConfig('waves/rs_sync_advanced/rs_send_bulk_upload');
|
| 43 |
+
if ($send_bulk_upload == NULL){
|
| 44 |
+
$send_bulk_upload = $this->sendBulkUpload;
|
| 45 |
+
}
|
| 46 |
+
return $send_bulk_upload;
|
| 47 |
+
}
|
| 48 |
|
| 49 |
+
public function useBulkCompression(){
|
| 50 |
+
$use_bulk_compression = Mage::getStoreConfig('waves/rs_sync_advanced/rs_use_bulk_compression');
|
| 51 |
+
if ($use_bulk_compression == NULL){
|
| 52 |
+
$use_bulk_compression = $this->useBulkCompression;
|
| 53 |
+
}
|
| 54 |
+
return $use_bulk_compression;
|
| 55 |
+
}
|
| 56 |
|
| 57 |
+
public function elementsPerPage(){
|
| 58 |
+
return $this->elementsPerPage;
|
| 59 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
public function writeToLog($msg, $category){
|
| 62 |
+
$msg = $msg . "\n";
|
| 63 |
+
$file = dirname(__FILE__) . '/retention_science_'. $category.'.log';
|
| 64 |
+
file_put_contents($file, $msg, FILE_APPEND);
|
| 65 |
+
}
|
| 66 |
|
| 67 |
+
public function get_last_processed_order_record_id(){
|
| 68 |
+
global $last_processed_order_record_id;
|
| 69 |
+
return $last_processed_order_record_id;
|
| 70 |
+
}
|
| 71 |
|
| 72 |
+
public function get_last_processed_user_entity_id(){
|
| 73 |
+
global $last_processed_user_entity_id;
|
| 74 |
+
return $last_processed_user_entity_id;
|
| 75 |
+
}
|
| 76 |
|
| 77 |
+
public function get_last_processed_product_entity_id(){
|
| 78 |
+
global $last_processed_product_entity_id;
|
| 79 |
+
return $last_processed_product_entity_id;
|
| 80 |
+
}
|
| 81 |
|
| 82 |
+
public function writeBulkUploadFile($entity_hash, $category, $timestamp){
|
| 83 |
+
$tmp_base = Mage::getBaseDir('tmp');
|
| 84 |
|
| 85 |
+
$msg = json_encode($entity_hash) . "\n";
|
| 86 |
+
$file = $tmp_base . '/rs_bulk_'. $category.'_'.$timestamp.'.log';
|
| 87 |
+
file_put_contents($file, $msg, FILE_APPEND);
|
| 88 |
+
}
|
|
|
|
| 89 |
|
| 90 |
+
public function sendDataSyncFiles($timestamp) {
|
| 91 |
+
$tmp_base = Mage::getBaseDir('tmp');
|
| 92 |
|
| 93 |
+
$types = array("categories", "items", "users", "orders", "orders_users");
|
| 94 |
+
$files = array();
|
| 95 |
+
$gzfiles = array();
|
| 96 |
+
foreach ($types as $type) {
|
| 97 |
+
$file = $tmp_base . '/rs_bulk_'. $type.'_'.$timestamp.'.log';
|
| 98 |
+
if (file_exists($file)) {
|
| 99 |
+
$files[$type] = $file;
|
| 100 |
+
if ($this->useBulkCompression()) {
|
| 101 |
+
$gzfile = $file . ".gz";
|
| 102 |
+
$fp = gzopen($gzfile, 'wb');
|
| 103 |
+
gzwrite($fp, file_get_contents($file));
|
| 104 |
+
gzclose($fp);
|
| 105 |
+
$gzfiles[$type] = $gzfile;
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
|
| 110 |
+
$files_to_send = (count($gzfiles) > 0) ? $gzfiles : $files;
|
| 111 |
|
| 112 |
+
if (count($files_to_send) > 0) {
|
| 113 |
+
$this->getRetentionScienceApiClient()->sync_data($files_to_send);
|
| 114 |
|
| 115 |
+
if ($this->removeFileAfterSend) {
|
| 116 |
+
array_map("unlink", array_values($files));
|
| 117 |
+
array_map("unlink", array_values($gzfiles));
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
|
| 122 |
+
public function productCallback($args){
|
| 123 |
|
| 124 |
+
global $last_processed_product_entity_id;
|
| 125 |
|
| 126 |
+
$timestamp = $args['timestamp'];
|
| 127 |
|
| 128 |
+
$product_id = $args['product_id'];
|
| 129 |
+
$product = Mage::getModel('catalog/product')->load($product_id);
|
| 130 |
+
$product_name = $product->getName();
|
| 131 |
|
| 132 |
+
// OLDER VERSIONS OF MAGENTO HAVE A FATAL ERROR for this bug in magento: http://www.magentocommerce.com/boards/viewthread/53871/#t215589
|
| 133 |
+
// MUST PATCH app/code/core/Mage/Catalog/Model/Product.php
|
| 134 |
+
$manufacturer = $product->getAttributeText('manufacturer');
|
| 135 |
+
$manufacturer = $manufacturer ? $manufacturer : null;
|
| 136 |
$model = $product->getSku();
|
| 137 |
+
$qty_stock = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();
|
| 138 |
+
$price = $product->getPrice();
|
| 139 |
+
if($product->getSpecialPrice()){
|
| 140 |
+
$price = $product->getSpecialPrice();
|
| 141 |
+
}
|
| 142 |
+
$price = number_format($price, 2, '.', '');
|
| 143 |
+
$active = ($product->isSalable()) ? true : false;
|
| 144 |
+
$images_url = array($product->getImageUrl());
|
| 145 |
+
$media_images = $product->getMediaGalleryImages();
|
| 146 |
+
foreach($media_images as $media_image){
|
| 147 |
+
$images_url[] = $media_image->getUrl();
|
| 148 |
+
}
|
| 149 |
+
$categories = $product->getCategoryIds();
|
| 150 |
+
$item_url = $product->getProductUrl();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
+
// Get the parent_item_record_id
|
| 153 |
+
$parent_record_id = null;
|
| 154 |
+
$product_type_id = $product->getTypeId();
|
| 155 |
+
if($product_type_id == "simple"){
|
| 156 |
+
$parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product_id);
|
| 157 |
+
if(!$parentIds){
|
| 158 |
+
$parentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product_id);
|
| 159 |
+
}
|
| 160 |
+
if(isset($parentIds[0])){
|
| 161 |
+
$parent_record_id = $parentIds[0];
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
|
| 165 |
+
$product_array = array(
|
| 166 |
+
'name'=> $product_name,
|
| 167 |
+
'manufacturer' => $manufacturer,
|
| 168 |
+
'model' => $model,
|
| 169 |
+
'quantity' => $qty_stock,
|
| 170 |
+
'price' => $price,
|
| 171 |
+
'active' => $active,
|
| 172 |
+
'image_list' => $images_url,
|
| 173 |
+
'item_url' => $item_url,
|
| 174 |
+
'parent_record_id' => $parent_record_id,
|
| 175 |
+
'attribute_1' => $product_type_id,
|
| 176 |
+
'categories' => $categories
|
| 177 |
+
);
|
| 178 |
|
| 179 |
+
if ($this->sendBulkUpload()){
|
| 180 |
+
$this->writeBulkUploadFile(array($product_id => $product_array), 'items', $timestamp);
|
| 181 |
+
} else {
|
| 182 |
+
try{
|
| 183 |
+
$this->getRetentionScienceApiClient()->update_item($product_id, $product_array);
|
| 184 |
+
} catch (Exception $e){
|
| 185 |
+
// do nothing
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
|
| 189 |
+
// Update this as we iterate
|
| 190 |
+
$last_processed_product_entity_id = $product_id;
|
| 191 |
+
}
|
| 192 |
|
| 193 |
+
public function userCallback($args){
|
| 194 |
+
global $last_processed_user_entity_id;
|
| 195 |
|
| 196 |
+
$timestamp = $args['timestamp'];
|
| 197 |
+
$user = Mage::getModel('customer/customer')->load($args['user_record_id']);
|
| 198 |
+
$email = $user->getEmail();
|
| 199 |
+
$user_entity_id = $user->getEntityId();
|
| 200 |
+
$user_record_id = md5(trim(strtolower($email)));
|
| 201 |
+
$fullName = $user->getName();
|
| 202 |
+
$address = Mage::getModel('customer/address')->load($user->getdefault_billing());
|
| 203 |
+
$address1 = $address->getStreetFull();
|
| 204 |
+
$address1 = str_replace("\n"," ",$address1);
|
| 205 |
+
$city = $address->getCity();
|
| 206 |
+
$regionModel = Mage::getModel('directory/region')->load($address->getRegionId());
|
| 207 |
+
$region = $regionModel->getName();
|
| 208 |
+
$zip = $address->getPostcode();
|
| 209 |
+
$country = $address->getCountryId();
|
| 210 |
+
$phone = $address->getTelephone();
|
| 211 |
+
$birthDate = $user->getDob();
|
| 212 |
+
$birthDate = explode('-',$birthDate);
|
| 213 |
+
$birth_year = $birthDate[0];
|
| 214 |
+
$gender = $user->getGender();
|
| 215 |
+
// $ipAddress = '117.196.42.219';
|
| 216 |
+
// $numberLogons = '2';
|
| 217 |
+
$accountCreatedAt = $user->getCreatedAt();
|
| 218 |
+
$accountCreatedAt = date("Y-m-d", Mage::getModel('core/date')->timestamp(strtotime($accountCreatedAt)));
|
| 219 |
|
| 220 |
+
$accountUpdatedDate = $user->getUpdatedAt();
|
| 221 |
+
$accountUpdatedAt = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(strtotime($accountUpdatedDate)));
|
| 222 |
|
| 223 |
+
if (!$this->sendBulkUpload()){
|
| 224 |
+
// only update some fields (like created_at) if this is a new user.
|
| 225 |
+
$user_exists_already = $this->getRetentionScienceApiClient()->user_exists($user_record_id);
|
| 226 |
+
$existing_user = ($user_exists_already) ? $this->getRetentionScienceApiClient()->show_user($user_record_id) : null;
|
| 227 |
+
}
|
| 228 |
|
| 229 |
+
$user_array = array();
|
| 230 |
+
if($email){
|
| 231 |
+
$user_array['email'] = $email;
|
| 232 |
+
}
|
| 233 |
+
if($fullName){
|
| 234 |
+
$user_array['full_name'] = $fullName;
|
| 235 |
+
}
|
| 236 |
+
if($address1){
|
| 237 |
+
$user_array['address1'] = $address1;
|
| 238 |
+
}
|
| 239 |
+
if($city){
|
| 240 |
+
$user_array['city'] = $city;
|
| 241 |
+
}
|
| 242 |
+
if($region){
|
| 243 |
+
$user_array['state'] = $region;
|
| 244 |
+
}
|
| 245 |
+
if($zip){
|
| 246 |
+
$user_array['zip'] = $zip;
|
| 247 |
+
}
|
| 248 |
+
if($country){
|
| 249 |
+
$user_array['country'] = $country;
|
| 250 |
+
}
|
| 251 |
+
if($phone){
|
| 252 |
+
$user_array['phone'] = $phone;
|
| 253 |
+
}
|
| 254 |
+
if($birth_year){
|
| 255 |
+
$user_array['birth_year'] = $birth_year;
|
| 256 |
+
}
|
| 257 |
+
if($gender){
|
| 258 |
+
$user_array['gender'] = $gender;
|
| 259 |
+
}
|
| 260 |
+
if($accountCreatedAt){
|
| 261 |
+
if ($this->sendBulkUpload()){
|
| 262 |
+
$user_array['account_created_on'] = $accountCreatedAt;
|
| 263 |
|
| 264 |
+
} else {
|
| 265 |
+
// Only send this if user has not already been created
|
| 266 |
+
if (!($user_exists_already) || ($existing_user && (strtotime($existing_user['account_created_on']) > strtotime($accountCreatedAt))) ){
|
| 267 |
+
$user_array['account_created_on'] = $accountCreatedAt;
|
| 268 |
+
}
|
| 269 |
+
}
|
| 270 |
+
}
|
| 271 |
+
if($accountUpdatedAt){
|
| 272 |
+
$user_array['last_logon_at'] = $accountUpdatedAt;
|
| 273 |
+
}
|
| 274 |
+
if ($this->logToFile()){
|
| 275 |
+
$this->writeToLog($user_record_id, 'users');
|
| 276 |
+
$this->writeToLog(http_build_query($user_array), 'users');
|
| 277 |
+
}
|
| 278 |
|
| 279 |
+
if ($this->sendBulkUpload()){
|
| 280 |
+
$this->writeBulkUploadFile(array($user_record_id => $user_array), 'users', $timestamp);
|
| 281 |
+
} else {
|
| 282 |
+
try{
|
| 283 |
+
$this->getRetentionScienceApiClient()->update_user($user_record_id, $user_array);
|
| 284 |
+
} catch (Exception $e){
|
| 285 |
+
// do nothing
|
| 286 |
+
}
|
| 287 |
+
}
|
| 288 |
+
// Update this as we iterate
|
| 289 |
+
$last_processed_user_entity_id = $user_entity_id;
|
| 290 |
+
}
|
|
|
|
|
|
|
| 291 |
|
| 292 |
+
public function orderCallback($args){
|
| 293 |
+
$timestamp = $args['timestamp'];
|
| 294 |
+
global $last_processed_order_record_id;
|
| 295 |
+
|
| 296 |
+
$order = Mage::getModel('sales/order')->load($args['order_record_id']);
|
| 297 |
+
$order_array = array();
|
| 298 |
+
$order_record_id = $order->getEntityId();
|
| 299 |
+
$orderAllItems = $order->getAllVisibleItems();
|
| 300 |
+
$order_item_array = array();
|
| 301 |
+
foreach($orderAllItems as $orderAllItem){
|
| 302 |
+
$item_record_id = $orderAllItem->getProductId();
|
| 303 |
+
$name = $orderAllItem->getName();
|
| 304 |
+
$quantity = (int) $orderAllItem->getQtyOrdered();
|
| 305 |
+
$price = $orderAllItem->getPrice();
|
| 306 |
+
$price = number_format($price, 2, '.', '');
|
| 307 |
+
$final_price = $price * $quantity;
|
| 308 |
+
$sku = $orderAllItem->getSku();
|
| 309 |
+
$productId = $orderAllItem->getProductId();
|
| 310 |
+
$product = Mage::getModel('catalog/product')->load($productId);
|
| 311 |
+
$categoryIds = $product->getCategoryIds();
|
| 312 |
+
$order_item_array[] = array(
|
| 313 |
+
'item_record_id' => $item_record_id,
|
| 314 |
+
'name' => $name,
|
| 315 |
+
'quantity' => $quantity,
|
| 316 |
+
'price' => $price,
|
| 317 |
+
'final_price' => $final_price,
|
| 318 |
+
'attribute_1' => $sku,
|
| 319 |
+
'categories' => $categoryIds
|
| 320 |
+
);
|
| 321 |
+
// save memory - Note, $product->clearInstance(); doesnt work on older magento installs
|
| 322 |
+
unset($product);
|
| 323 |
+
}
|
| 324 |
+
unset($orderAllItems);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
|
| 326 |
+
$user_record_id = md5(trim(strtolower($order->getCustomerEmail())));
|
| 327 |
+
if($order->getCustomerIsGuest()){
|
| 328 |
+
$email = $order->getCustomerEmail();
|
| 329 |
+
$user_record_id = md5(trim(strtolower($email)));
|
| 330 |
|
| 331 |
+
// get billing address
|
| 332 |
+
$address = $order->getBillingAddress();
|
| 333 |
+
$fullName = $order->getCustomerFirstname()." ".$order->getCustomerLastname();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
|
| 335 |
+
$address1 = $address->getStreetFull();
|
| 336 |
+
$address1 = str_replace("\n"," ",$address1);
|
| 337 |
+
$city = $address->getCity();
|
| 338 |
+
$regionModel = Mage::getModel('directory/region')->load($address->getRegionId());
|
| 339 |
+
$region = $regionModel->getName();
|
| 340 |
+
$zip = $address->getPostcode();
|
| 341 |
+
$country = $address->getCountryId();
|
| 342 |
+
$phone = $address->getTelephone();
|
| 343 |
+
$accountCreatedAt = $order->getCreatedAt();
|
| 344 |
+
$accountUpdatedAt = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(strtotime($accountCreatedAt)));
|
| 345 |
+
$accountCreatedAt = date("Y-m-d", Mage::getModel('core/date')->timestamp(strtotime($accountCreatedAt)));
|
| 346 |
|
| 347 |
+
if (!$this->sendBulkUpload()){
|
| 348 |
+
// only update some fields (like created_at) if this is a new user.
|
| 349 |
+
$user_exists_already = $this->getRetentionScienceApiClient()->user_exists($user_record_id);
|
| 350 |
+
$existing_user = ($user_exists_already) ? $this->getRetentionScienceApiClient()->show_user($user_record_id) : null;
|
| 351 |
+
}
|
| 352 |
|
| 353 |
+
// send this user to api as well
|
| 354 |
+
$user_array = array();
|
| 355 |
+
if($email){
|
| 356 |
+
$user_array['email'] = $email;
|
| 357 |
+
}
|
| 358 |
+
if($fullName){
|
| 359 |
+
$user_array['full_name'] = $fullName;
|
| 360 |
+
}
|
| 361 |
+
if($address1){
|
| 362 |
+
$user_array['address1'] = $address1;
|
| 363 |
+
}
|
| 364 |
+
if($city){
|
| 365 |
+
$user_array['city'] = $city;
|
| 366 |
+
}
|
| 367 |
+
if($region){
|
| 368 |
+
$user_array['state'] = $region;
|
| 369 |
+
}
|
| 370 |
+
if($zip){
|
| 371 |
+
$user_array['zip'] = $zip;
|
| 372 |
+
}
|
| 373 |
+
if($country){
|
| 374 |
+
$user_array['country'] = $country;
|
| 375 |
+
}
|
| 376 |
+
if($phone){
|
| 377 |
+
$user_array['phone'] = $phone;
|
| 378 |
+
}
|
| 379 |
+
if($accountCreatedAt){
|
| 380 |
+
if ($this->sendBulkUpload()){
|
| 381 |
+
$user_array['account_created_on'] = $accountCreatedAt;
|
| 382 |
|
| 383 |
+
} else {
|
| 384 |
+
if (!($user_exists_already)){
|
| 385 |
+
$this->writeToLog("User does not exist yet ***** - creating with account_created_on as [" . $accountCreatedAt . ']', 'order_users');
|
| 386 |
+
} else if ($existing_user) {
|
| 387 |
+
$this->writeToLog(http_build_query($existing_user), 'existing_users');
|
| 388 |
+
$themsg = "Existing user is PRESENT. His account_created_on is [" . $existing_user['account_created_on'] . "]. My accountCreatedAt is [" . $accountCreatedAt . "]";
|
| 389 |
+
$this->writeToLog($themsg, 'order_users');
|
| 390 |
+
}
|
| 391 |
|
| 392 |
+
if (!($user_exists_already) || ($existing_user && (strtotime($existing_user['account_created_on']) > strtotime($accountCreatedAt))) ){
|
| 393 |
+
$user_array['account_created_on'] = $accountCreatedAt;
|
| 394 |
+
}
|
| 395 |
+
}
|
| 396 |
+
}
|
| 397 |
+
if($accountUpdatedAt){
|
| 398 |
+
$user_array['last_logon_at'] = $accountUpdatedAt;
|
| 399 |
+
}
|
| 400 |
|
| 401 |
+
if ($this->logToFile()){
|
| 402 |
+
$this->writeToLog($user_record_id, 'order_users');
|
| 403 |
+
$this->writeToLog(http_build_query($user_array), 'order_users');
|
| 404 |
+
}
|
| 405 |
+
try{
|
| 406 |
+
if ($this->sendBulkUpload()){
|
| 407 |
+
$this->writeBulkUploadFile(array($user_record_id => $user_array), 'orders_users', $timestamp);
|
| 408 |
+
} else {
|
| 409 |
+
$this->getRetentionScienceApiClient()->update_user($user_record_id, $user_array);
|
| 410 |
+
}
|
| 411 |
+
} catch (Exception $e){
|
| 412 |
+
// do nothing
|
| 413 |
+
}
|
| 414 |
+
}
|
| 415 |
|
| 416 |
+
$total_price = $order->getBaseSubtotal();
|
| 417 |
+
$total_price = number_format($total_price, 2, '.', '');
|
| 418 |
+
$discount_amount = $order->getBaseDiscountAmount();
|
| 419 |
+
$shipping_amount = $order->getShippingAmount();
|
| 420 |
+
$tax_amount = $order->getBaseTaxAmount();
|
| 421 |
+
$date = $order->getCreatedAt();
|
| 422 |
+
$ordered_at = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(strtotime($date)));
|
| 423 |
+
$payment_method = $order->getPayment()->getMethodInstance()->getTitle();
|
| 424 |
+
$order_array = array(
|
| 425 |
+
'user_record_id' => $user_record_id,
|
| 426 |
+
'total_price' => $total_price,
|
| 427 |
+
'discount_amount' => $discount_amount,
|
| 428 |
+
'shipping_amount' => $shipping_amount,
|
| 429 |
+
'tax_amount' => $tax_amount,
|
| 430 |
+
'ordered_at' => $ordered_at,
|
| 431 |
+
'payment_method' => $payment_method,
|
| 432 |
+
'order_items'=> $order_item_array
|
| 433 |
+
);
|
| 434 |
+
if ($this->sendBulkUpload()){
|
| 435 |
+
$this->writeBulkUploadFile(array($order_record_id => $order_array), 'orders', $timestamp);
|
| 436 |
+
} else {
|
| 437 |
+
try {
|
| 438 |
+
$this->getRetentionScienceApiClient()->update_order($order_record_id, $order_array);
|
| 439 |
+
} catch (Exception $e){
|
| 440 |
+
// do nothing
|
| 441 |
+
}
|
| 442 |
+
}
|
| 443 |
|
| 444 |
+
// Update this as we iterate
|
| 445 |
+
$last_processed_order_record_id = $order_record_id;
|
| 446 |
+
// Release memory. Note: $order->clearInstance(); doesnt work on older magento ver
|
| 447 |
+
unset($order_array);
|
| 448 |
+
unset($order);
|
| 449 |
+
}
|
|
|
|
|
|
|
| 450 |
|
| 451 |
+
public function coreBlockAbstractPrepareLayoutAfter(Varien_Event_Observer $observer)
|
| 452 |
{
|
| 453 |
if (Mage::app()->getFrontController()->getAction()->getFullActionName() === 'adminhtml_dashboard_index')
|
| 454 |
{
|
| 483 |
return $rscore_json;
|
| 484 |
}
|
| 485 |
|
| 486 |
+
public function syncData() {
|
| 487 |
+
if (Mage::getStoreConfig('waves/retentionscience_settings/enable') == 1) {
|
| 488 |
+
$phpbin = $this->getPhpBin();
|
| 489 |
+
$sync_data_script = escapeshellarg(dirname(__FILE__) . "/rs_sync_data.php");
|
| 490 |
|
| 491 |
+
$store_id = Mage::getStoreConfig('waves/retentionscience_settings/store_id');
|
| 492 |
+
$valid_store_ids = array_keys(Mage::app()->getStores());
|
| 493 |
|
| 494 |
+
if (in_array($store_id, $valid_store_ids)) {
|
| 495 |
+
exec("$phpbin $sync_data_script $store_id > /dev/null &");
|
| 496 |
+
} else {
|
| 497 |
+
Mage::getSingleton('core/session')->addError("You must select a valid Store ID!");
|
| 498 |
+
}
|
| 499 |
+
} else {
|
| 500 |
+
Mage::getSingleton('core/session')->addError("You can't sync data unless Retention Science is enabled!");
|
| 501 |
+
}
|
| 502 |
+
}
|
| 503 |
}
|
app/code/community/RetentionScience/Waves/Model/Source/Categorytree.php
CHANGED
|
@@ -34,24 +34,9 @@ class RetentionScience_Waves_Model_Source_Categorytree extends Mage_Eav_Model_En
|
|
| 34 |
->addAttributeToSelect('*')
|
| 35 |
;
|
| 36 |
$categories->getSelect()->order("level asc");
|
| 37 |
-
|
| 38 |
-
// $categories = Mage::getModel('catalog/category')->getCollection()
|
| 39 |
-
//
|
| 40 |
-
// ->addAttributeToSelect('name')
|
| 41 |
-
// ->addAttributeToSelect('url_key')
|
| 42 |
-
// ->addAttributeToSelect('my_attribute')
|
| 43 |
-
// ->setLoadProductCount(true)
|
| 44 |
-
// ->addAttributeToSort('parent_record_id', 'ASC')
|
| 45 |
-
// ->addAttributeToSort('entity_id', 'ASC')
|
| 46 |
-
// //->addAttributeToFilter('is_active',array('eq'=>true))
|
| 47 |
-
// ->load();
|
| 48 |
$this->_options['categories'] = $categories;
|
| 49 |
}
|
| 50 |
-
|
| 51 |
-
* Retrieve all options array
|
| 52 |
-
*
|
| 53 |
-
* @return array
|
| 54 |
-
*/
|
| 55 |
public function getAllOptions()
|
| 56 |
{
|
| 57 |
if (!$this->_options) {
|
| 34 |
->addAttributeToSelect('*')
|
| 35 |
;
|
| 36 |
$categories->getSelect()->order("level asc");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
$this->_options['categories'] = $categories;
|
| 38 |
}
|
| 39 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
public function getAllOptions()
|
| 41 |
{
|
| 42 |
if (!$this->_options) {
|
app/code/community/RetentionScience/Waves/Model/Source/Cronconfig.php
CHANGED
|
@@ -1,33 +1,31 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
class RetentionScience_Waves_Model_Source_Cronconfig extends Mage_Core_Model_Config_Data
|
| 4 |
-
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
$cron_expr_string = $this->getValue();
|
| 15 |
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
|
| 33 |
-
|
| 1 |
<?php
|
| 2 |
|
| 3 |
class RetentionScience_Waves_Model_Source_Cronconfig extends Mage_Core_Model_Config_Data
|
| 4 |
+
{
|
| 5 |
|
| 6 |
+
protected function _afterSave()
|
| 7 |
+
{
|
| 8 |
+
// category, product, user, order
|
| 9 |
+
$rs_cron_job = $this->getFieldConfig()->rs_cron_job;
|
| 10 |
+
$cron_string_path = 'crontab/jobs/' . $rs_cron_job . '/schedule/cron_expr';
|
| 11 |
+
$cron_model_path = 'crontab/jobs/' . $rs_cron_job . '/run/model';
|
| 12 |
+
$cron_expr_string = $this->getValue();
|
|
|
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
+
try {
|
| 16 |
+
Mage::getModel('core/config_data')
|
| 17 |
+
->load($cron_string_path, 'path')
|
| 18 |
+
->setValue($cron_expr_string)
|
| 19 |
+
->setPath($cron_string_path)
|
| 20 |
+
->save();
|
| 21 |
+
Mage::getModel('core/config_data')
|
| 22 |
+
->load($cron_model_path, 'path')
|
| 23 |
+
->setValue((string) Mage::getConfig()->getNode($cron_model_path))
|
| 24 |
+
->setPath($cron_model_path)
|
| 25 |
+
->save();
|
| 26 |
+
} catch (Exception $e) {
|
| 27 |
+
throw new Exception(Mage::helper('cron')->__('Unable to save the cron expression.'));
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
|
| 31 |
+
}
|
app/code/community/RetentionScience/Waves/Model/Source/Rscoredata.php
CHANGED
|
@@ -42,7 +42,6 @@ class RetentionScience_Waves_Model_Source_Rscoredata
|
|
| 42 |
|
| 43 |
private function getEngagementRate()
|
| 44 |
{
|
| 45 |
-
// orders.select("distinct user_id").count.to_f/users.count.to_f
|
| 46 |
$customer_table = $this->resource->getTableName('customer_entity');
|
| 47 |
$order_table = $this->resource->getTableName('sales_flat_order');
|
| 48 |
$query = "SELECT
|
| 42 |
|
| 43 |
private function getEngagementRate()
|
| 44 |
{
|
|
|
|
| 45 |
$customer_table = $this->resource->getTableName('customer_entity');
|
| 46 |
$order_table = $this->resource->getTableName('sales_flat_order');
|
| 47 |
$query = "SELECT
|
app/code/community/RetentionScience/Waves/Model/retention_science_api.php
CHANGED
|
@@ -10,195 +10,195 @@ Released under the GNU General Public License
|
|
| 10 |
*/
|
| 11 |
class RetentionScienceApi {
|
| 12 |
const API_DEV_URL = 'http://api.rsapi.dev';
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
|
| 183 |
-
|
| 184 |
-
|
| 185 |
$url = 'r_scores/calculate';
|
| 186 |
$response = $this->perform_call($url, array('data' => json_encode($rscore_data_array)), false, true);
|
| 187 |
return $this->handle_response($response);
|
| 188 |
-
|
| 189 |
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
}
|
| 203 |
|
| 204 |
|
| 10 |
*/
|
| 11 |
class RetentionScienceApi {
|
| 12 |
const API_DEV_URL = 'http://api.rsapi.dev';
|
| 13 |
+
const API_TEST_URL = 'http://api.retentionsandbox.com';
|
| 14 |
+
const API_URL = 'http://api.retentionscience.com';
|
| 15 |
+
const API_PORT = 80;
|
| 16 |
+
const API_VERSION = '1';
|
| 17 |
+
|
| 18 |
+
private $password;
|
| 19 |
+
private $time_out = 60;
|
| 20 |
+
private $username;
|
| 21 |
+
private $testmode;
|
| 22 |
+
|
| 23 |
+
// class methods
|
| 24 |
+
public function __construct($username = null, $password = null, $testmode=false) {
|
| 25 |
+
if($username !== null) $this->set_username($username);
|
| 26 |
+
if($password !== null) $this->set_password($password);
|
| 27 |
+
if($testmode) $this->set_testmode($testmode);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
private function perform_call($url, $params = array(), $authenticate = false, $use_post = true) {
|
| 31 |
+
// redefine
|
| 32 |
+
$url = (string) $url;
|
| 33 |
+
$aParameters = (array) $params;
|
| 34 |
+
$authenticate = (bool) $authenticate;
|
| 35 |
+
$use_post = (bool) $use_post;
|
| 36 |
+
|
| 37 |
+
// build url
|
| 38 |
+
$request_url = parse_url('http://' . $_SERVER['HTTP_HOST']);
|
| 39 |
|
| 40 |
+
if ($request_url['host'] == 'rsapi.dev' || $request_url['host'] == 'magento.dev') {
|
| 41 |
+
$url = self::API_DEV_URL .'/' . $url;
|
| 42 |
+
} elseif ($this->get_testmode()) {
|
| 43 |
+
$url = self::API_TEST_URL .'/' . $url;
|
| 44 |
+
} else {
|
| 45 |
+
$url = self::API_URL .'/' . $url;
|
| 46 |
+
}
|
| 47 |
|
| 48 |
+
// validate needed authentication
|
| 49 |
+
if($authenticate && ($this->get_username() == '' || $this->get_password() == '')) {
|
| 50 |
+
throw new RetentionScienceException('No username or password was set.');
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
// build GET URL if not using post
|
| 54 |
+
if(!empty($params) && !$use_post){
|
| 55 |
+
$url .= '?'. http_build_query( $params );
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
// set options
|
| 59 |
+
$options[CURLOPT_URL] = $url;
|
| 60 |
+
$options[CURLOPT_PORT] = self::API_PORT;
|
| 61 |
+
$options[CURLOPT_USERAGENT] = $this->get_user_agent();
|
| 62 |
+
// follow on only if allowed - 20120221
|
| 63 |
+
if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')){
|
| 64 |
+
$options[CURLOPT_FOLLOWLOCATION] = true;
|
| 65 |
+
}
|
| 66 |
+
$options[CURLOPT_RETURNTRANSFER] = true;
|
| 67 |
+
$options[CURLOPT_TIMEOUT] = (int) $this->time_out;
|
| 68 |
+
|
| 69 |
+
// HTTP basic auth
|
| 70 |
+
if($authenticate) {
|
| 71 |
+
$options[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
|
| 72 |
+
$options[CURLOPT_USERPWD] = $this->get_username() .':'. $this->get_password();
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
// build post params if $use_post
|
| 76 |
+
if(!empty($params) && $use_post) {
|
| 77 |
+
$options[CURLOPT_POST] = true;
|
| 78 |
+
$options[CURLOPT_POSTFIELDS] = $params;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
// curl init
|
| 82 |
+
$curl = curl_init();
|
| 83 |
+
// set options
|
| 84 |
+
curl_setopt_array($curl, $options);
|
| 85 |
+
// execute
|
| 86 |
+
$response = curl_exec($curl);
|
| 87 |
+
$headers = curl_getinfo($curl);
|
| 88 |
+
// fetch errors and status code
|
| 89 |
+
$errorNumber = curl_errno($curl);
|
| 90 |
+
$errorMessage = curl_error($curl);
|
| 91 |
+
$http_status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
| 92 |
+
|
| 93 |
+
if ($errorNumber != 0) {
|
| 94 |
+
$response = 'cURL ERROR: [' . $errorNumber . "] " . $errorMessage;
|
| 95 |
+
}
|
| 96 |
+
// close
|
| 97 |
+
curl_close($curl);
|
| 98 |
+
return array('response_code' => $http_status_code,
|
| 99 |
+
'response' => $response);
|
| 100 |
+
}
|
| 101 |
|
| 102 |
+
private function handle_response($response){
|
| 103 |
+
// decode the returned json
|
| 104 |
+
if ($response['response_code'] == 200 || $response['response_code'] == 201 ){
|
| 105 |
+
return $response['response'];
|
| 106 |
+
} else {
|
| 107 |
+
throw new RetentionScienceException($response['response_code'] . ' - ' . $response['response']);
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
// Getters
|
| 113 |
+
private function get_password(){
|
| 114 |
+
return (string) $this->password;
|
| 115 |
+
}
|
| 116 |
+
private function get_user_agent(){
|
| 117 |
+
return (string) 'Retention Science PHP API Client / v'. self::API_VERSION;
|
| 118 |
+
}
|
| 119 |
+
private function get_username(){
|
| 120 |
+
return (string) $this->username;
|
| 121 |
+
}
|
| 122 |
+
private function get_testmode(){
|
| 123 |
+
return (boolean) $this->testmode;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
// Setters
|
| 127 |
+
private function set_username($username){
|
| 128 |
+
$this->username = (string) $username;
|
| 129 |
+
}
|
| 130 |
+
private function set_password($password){
|
| 131 |
+
$this->password = (string) $password;
|
| 132 |
+
}
|
| 133 |
+
private function set_testmode($testmode){
|
| 134 |
+
$this->testmode = (boolean) $testmode;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
/* Users resource */
|
| 138 |
+
public function user_exists($record_id) {
|
| 139 |
+
$url = 'users/exists/' . $record_id;
|
| 140 |
+
$response = $this->perform_call($url, array(), true, false);
|
| 141 |
+
return ($this->handle_response($response) == 'true');
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
public function get_last_user_record_id() {
|
| 145 |
+
$url = 'users/last_record_id';
|
| 146 |
+
$response = $this->perform_call($url, array(), true, false);
|
| 147 |
+
return $this->handle_response($response);
|
| 148 |
+
}
|
| 149 |
|
| 150 |
+
public function show_user($record_id) {
|
| 151 |
+
$url = 'users/show/' . urlencode($record_id);
|
| 152 |
+
$response = $this->perform_call($url, array(), true, false);
|
| 153 |
+
return json_decode($this->handle_response($response), true);
|
| 154 |
+
}
|
| 155 |
|
| 156 |
+
/* Orders resource */
|
| 157 |
+
public function get_last_order_record_id() {
|
| 158 |
+
$url = 'orders/last_record_id';
|
| 159 |
+
$response = $this->perform_call($url, array(), true, false);
|
| 160 |
+
return $this->handle_response($response);
|
| 161 |
+
}
|
| 162 |
|
| 163 |
+
public function show_order($record_id) {
|
| 164 |
+
$url = 'orders/show/' . urlencode($record_id);
|
| 165 |
+
$response = $this->perform_call($url, array(), true, false);
|
| 166 |
+
return json_decode($this->handle_response($response), true);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
/* Items resource */
|
| 170 |
+
public function show_item($record_id) {
|
| 171 |
+
$url = 'items/show/' . urlencode($record_id);
|
| 172 |
+
$response = $this->perform_call($url, array(), true, false);
|
| 173 |
+
return json_decode($this->handle_response($response), true);
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
/* Categories resource */
|
| 177 |
+
public function show_category($record_id) {
|
| 178 |
+
$url = 'categories/show/' . urlencode($record_id);
|
| 179 |
+
$response = $this->perform_call($url, array(), true, false);
|
| 180 |
+
return json_decode($this->handle_response($response), true);
|
| 181 |
+
}
|
| 182 |
|
| 183 |
+
/* RScore resource */
|
| 184 |
+
public function calculate_rscore($rscore_data_array) {
|
| 185 |
$url = 'r_scores/calculate';
|
| 186 |
$response = $this->perform_call($url, array('data' => json_encode($rscore_data_array)), false, true);
|
| 187 |
return $this->handle_response($response);
|
| 188 |
+
}
|
| 189 |
|
| 190 |
+
/* Data Sync */
|
| 191 |
+
public function sync_data($file_hash) {
|
| 192 |
+
$url = 'bulk_import/import';
|
| 193 |
|
| 194 |
+
$upload_files = array();
|
| 195 |
+
foreach ($file_hash as $type => $file) {
|
| 196 |
+
$upload_files[$type] = "@$file";
|
| 197 |
+
}
|
| 198 |
|
| 199 |
+
$response = $this->perform_call($url, $upload_files, true, true);
|
| 200 |
+
return $this->handle_response($response);
|
| 201 |
+
}
|
| 202 |
}
|
| 203 |
|
| 204 |
|
app/code/community/RetentionScience/Waves/Model/rs_get_save_config.php
CHANGED
|
@@ -1,29 +1,28 @@
|
|
| 1 |
<?php
|
|
|
|
|
|
|
|
|
|
| 2 |
define('MAGENTO', realpath(dirname(__FILE__)));
|
| 3 |
require_once MAGENTO . '/../../../../../../app/Mage.php';
|
| 4 |
-
// require_once '/Users/--/Sites/magento/app/Mage.php';
|
| 5 |
-
// require_once '/Applications/MAMP/htdocs/magento/app/Mage.php';
|
| 6 |
|
| 7 |
-
//umask(0);
|
| 8 |
$store_id = $argv[1];
|
| 9 |
$get_save = $argv[2];
|
| 10 |
$key = $argv[3];
|
| 11 |
|
| 12 |
try {
|
| 13 |
-
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
$
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
die(0);
|
| 25 |
} catch (Exception $e){
|
| 26 |
-
|
| 27 |
-
|
| 28 |
}
|
| 29 |
|
| 1 |
<?php
|
| 2 |
+
// Get or Save a store config value
|
| 3 |
+
// This will make a new db connection so it's guaranteed not to result in connection-timeout
|
| 4 |
+
|
| 5 |
define('MAGENTO', realpath(dirname(__FILE__)));
|
| 6 |
require_once MAGENTO . '/../../../../../../app/Mage.php';
|
|
|
|
|
|
|
| 7 |
|
|
|
|
| 8 |
$store_id = $argv[1];
|
| 9 |
$get_save = $argv[2];
|
| 10 |
$key = $argv[3];
|
| 11 |
|
| 12 |
try {
|
| 13 |
+
Mage::app()->setCurrentStore($store_id);
|
| 14 |
|
| 15 |
+
$result = '';
|
| 16 |
+
if ($get_save == 'GET'){
|
| 17 |
+
$result = Mage::getStoreConfig($key);
|
| 18 |
+
echo $result;
|
| 19 |
+
} else if ($get_save == 'SAVE'){
|
| 20 |
+
$val = $argv[4];
|
| 21 |
+
$result = Mage::getModel('core/config')->saveConfig($key, $val);
|
| 22 |
+
}
|
| 23 |
+
die(0);
|
|
|
|
| 24 |
} catch (Exception $e){
|
| 25 |
+
Mage::logException($e);
|
| 26 |
+
die(1);
|
| 27 |
}
|
| 28 |
|
app/code/community/RetentionScience/Waves/Model/rs_send_categories.php
CHANGED
|
@@ -1,28 +1,27 @@
|
|
| 1 |
<?php
|
|
|
|
|
|
|
| 2 |
define('MAGENTO', realpath(dirname(__FILE__)));
|
| 3 |
require_once MAGENTO . '/../../../../../../app/Mage.php';
|
| 4 |
-
// require_once '/Users/--/Sites/magento/app/Mage.php';
|
| 5 |
-
// require_once '/Applications/MAMP/htdocs/magento/app/Mage.php';
|
| 6 |
|
| 7 |
-
//umask(0);
|
| 8 |
$store_id = $argv[1];
|
| 9 |
$timestamp = $argv[2];
|
| 10 |
|
| 11 |
try {
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
} catch (Exception $e){
|
| 26 |
-
|
| 27 |
-
|
| 28 |
}
|
| 1 |
<?php
|
| 2 |
+
// Generates all the categories in a separate PHP process for memory efficiency
|
| 3 |
+
|
| 4 |
define('MAGENTO', realpath(dirname(__FILE__)));
|
| 5 |
require_once MAGENTO . '/../../../../../../app/Mage.php';
|
|
|
|
|
|
|
| 6 |
|
|
|
|
| 7 |
$store_id = $argv[1];
|
| 8 |
$timestamp = $argv[2];
|
| 9 |
|
| 10 |
try {
|
| 11 |
+
Mage::app()->setCurrentStore($store_id);
|
| 12 |
+
$observer = new RetentionScience_Waves_Model_Observer();
|
| 13 |
+
$categorytree = Mage::getModel('waves/source_categorytree')->getAllOptions();
|
| 14 |
|
| 15 |
+
foreach($categorytree as $category){
|
| 16 |
+
$parentId = ($category->getParentId())?$category->getParentId():null;
|
| 17 |
+
$categoryId = $category->getEntityId();
|
| 18 |
+
$categoryName = $category->getName();
|
| 19 |
+
$categoryDescription = $category->getDescripton();
|
| 20 |
+
$category_array = array('name' => $categoryName, 'description' => $categoryDescription, 'parent_record_id' => $parentId);
|
| 21 |
+
$observer->writeBulkUploadFile(array($categoryId => $category_array), 'categories', $timestamp);
|
| 22 |
+
}
|
| 23 |
+
die(0);
|
| 24 |
} catch (Exception $e){
|
| 25 |
+
Mage::logException($e);
|
| 26 |
+
die(1);
|
| 27 |
}
|
app/code/community/RetentionScience/Waves/Model/rs_send_orders.php
CHANGED
|
@@ -1,44 +1,38 @@
|
|
| 1 |
<?php
|
|
|
|
| 2 |
|
| 3 |
define('MAGENTO', realpath(dirname(__FILE__)));
|
| 4 |
require_once MAGENTO . '/../../../../../../app/Mage.php';
|
| 5 |
-
// require_once '/Users/-/Sites/magento/app/Mage.php';
|
| 6 |
-
// require_once '/Applications/MAMP/htdocs/magento/app/Mage.php';
|
| 7 |
|
| 8 |
-
|
| 9 |
-
//umask(0);
|
| 10 |
$store_id = $argv[1];
|
| 11 |
$timestamp = $argv[2];
|
| 12 |
$page_counter = $argv[3];
|
| 13 |
$last_order_record_id = $argv[4];
|
| 14 |
|
| 15 |
-
// Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
|
| 16 |
Mage::app()->setCurrentStore($store_id);
|
| 17 |
|
| 18 |
|
| 19 |
-
#echo "Running rs_send_orders.php with arguments $store_id $timestamp $page_counter $last_order_record_id \n";
|
| 20 |
|
| 21 |
$observer = new RetentionScience_Waves_Model_Observer();
|
| 22 |
$elements_per_page = $observer->elementsPerPage();
|
| 23 |
-
|
| 24 |
$orderCollection = Mage::getModel('sales/order')->getCollection();
|
| 25 |
$orderCollection->addAttributeToSelect('entity_id');
|
| 26 |
if($last_order_record_id>0){
|
| 27 |
-
|
| 28 |
}
|
| 29 |
|
| 30 |
$orderCollection->setPage($page_counter, $elements_per_page);
|
| 31 |
|
| 32 |
try {
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
|
| 39 |
} catch (Exception $e){
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
}
|
| 44 |
|
| 1 |
<?php
|
| 2 |
+
// Generates all the orders in a separate PHP process for memory efficiency
|
| 3 |
|
| 4 |
define('MAGENTO', realpath(dirname(__FILE__)));
|
| 5 |
require_once MAGENTO . '/../../../../../../app/Mage.php';
|
|
|
|
|
|
|
| 6 |
|
|
|
|
|
|
|
| 7 |
$store_id = $argv[1];
|
| 8 |
$timestamp = $argv[2];
|
| 9 |
$page_counter = $argv[3];
|
| 10 |
$last_order_record_id = $argv[4];
|
| 11 |
|
|
|
|
| 12 |
Mage::app()->setCurrentStore($store_id);
|
| 13 |
|
| 14 |
|
|
|
|
| 15 |
|
| 16 |
$observer = new RetentionScience_Waves_Model_Observer();
|
| 17 |
$elements_per_page = $observer->elementsPerPage();
|
|
|
|
| 18 |
$orderCollection = Mage::getModel('sales/order')->getCollection();
|
| 19 |
$orderCollection->addAttributeToSelect('entity_id');
|
| 20 |
if($last_order_record_id>0){
|
| 21 |
+
$orderCollection->addFieldToFilter('entity_id', array('gt'=>$last_order_record_id));
|
| 22 |
}
|
| 23 |
|
| 24 |
$orderCollection->setPage($page_counter, $elements_per_page);
|
| 25 |
|
| 26 |
try {
|
| 27 |
+
foreach($orderCollection as $order){
|
| 28 |
+
$observer->orderCallback(array('order_record_id' => $order->getEntityId(), 'timestamp' => $timestamp));
|
| 29 |
+
}
|
| 30 |
+
echo $observer->get_last_processed_order_record_id();
|
| 31 |
+
die(0);
|
| 32 |
|
| 33 |
} catch (Exception $e){
|
| 34 |
+
Mage::logException($e);
|
| 35 |
+
echo $observer->get_last_processed_order_record_id();
|
| 36 |
+
die(1);
|
| 37 |
}
|
| 38 |
|
app/code/community/RetentionScience/Waves/Model/rs_send_products.php
CHANGED
|
@@ -1,40 +1,32 @@
|
|
| 1 |
<?php
|
|
|
|
| 2 |
|
| 3 |
define('MAGENTO', dirname(__FILE__));
|
| 4 |
require_once MAGENTO . '/../../../../../../app/Mage.php';
|
| 5 |
-
// require_once '/Users/--/Sites/magento/app/Mage.php';
|
| 6 |
-
// require_once '/Applications/MAMP/htdocs/magento/app/Mage.php';
|
| 7 |
-
|
| 8 |
-
//umask(0);
|
| 9 |
-
|
| 10 |
|
| 11 |
$store_id = $argv[1];
|
| 12 |
$timestamp = $argv[2];
|
| 13 |
$page_counter = $argv[3];
|
| 14 |
|
| 15 |
-
// Mage_Core_Model_App::ADMIN_STORE_ID
|
| 16 |
Mage::app()->setCurrentStore($store_id);
|
| 17 |
-
|
| 18 |
-
// $msg = "Running rs_send_products.php with arguments $store_id $timestamp $page_counter \n";
|
| 19 |
-
|
| 20 |
$observer = new RetentionScience_Waves_Model_Observer();
|
| 21 |
$elements_per_page = $observer->elementsPerPage();
|
| 22 |
|
|
|
|
| 23 |
$productCollection = Mage::getModel('catalog/product')->getCollection();
|
| 24 |
$productCollection->addAttributeToSelect('entity_id')->addAttributeToSelect('*');
|
| 25 |
-
|
| 26 |
$productCollection->setPage($page_counter, $elements_per_page);
|
| 27 |
|
| 28 |
try {
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
|
| 35 |
} catch (Exception $e){
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
}
|
| 40 |
|
| 1 |
<?php
|
| 2 |
+
// Generates all the items in a separate PHP process for memory efficiency
|
| 3 |
|
| 4 |
define('MAGENTO', dirname(__FILE__));
|
| 5 |
require_once MAGENTO . '/../../../../../../app/Mage.php';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
$store_id = $argv[1];
|
| 8 |
$timestamp = $argv[2];
|
| 9 |
$page_counter = $argv[3];
|
| 10 |
|
|
|
|
| 11 |
Mage::app()->setCurrentStore($store_id);
|
|
|
|
|
|
|
|
|
|
| 12 |
$observer = new RetentionScience_Waves_Model_Observer();
|
| 13 |
$elements_per_page = $observer->elementsPerPage();
|
| 14 |
|
| 15 |
+
// Retrieve products collection
|
| 16 |
$productCollection = Mage::getModel('catalog/product')->getCollection();
|
| 17 |
$productCollection->addAttributeToSelect('entity_id')->addAttributeToSelect('*');
|
|
|
|
| 18 |
$productCollection->setPage($page_counter, $elements_per_page);
|
| 19 |
|
| 20 |
try {
|
| 21 |
+
foreach($productCollection as $product){
|
| 22 |
+
$observer->productCallback(array('product_id' => $product->getId(), 'timestamp' => $timestamp));
|
| 23 |
+
}
|
| 24 |
+
echo $observer->get_last_processed_product_entity_id();
|
| 25 |
+
die(0);
|
| 26 |
|
| 27 |
} catch (Exception $e){
|
| 28 |
+
Mage::logException($e);
|
| 29 |
+
echo $observer->get_last_processed_product_entity_id();
|
| 30 |
+
die(1);
|
| 31 |
}
|
| 32 |
|
app/code/community/RetentionScience/Waves/Model/rs_send_users.php
CHANGED
|
@@ -1,44 +1,37 @@
|
|
| 1 |
<?php
|
|
|
|
| 2 |
|
| 3 |
define('MAGENTO', realpath(dirname(__FILE__)));
|
| 4 |
require_once MAGENTO . '/../../../../../../app/Mage.php';
|
| 5 |
-
// require_once '/Users/-/Sites/magento/app/Mage.php';
|
| 6 |
-
// require_once '/Applications/MAMP/htdocs/magento/app/Mage.php';
|
| 7 |
|
| 8 |
-
|
| 9 |
-
//umask(0);
|
| 10 |
$store_id = $argv[1];
|
| 11 |
$timestamp = $argv[2];
|
| 12 |
$page_counter = $argv[3];
|
| 13 |
$last_user_record_id = $argv[4];
|
| 14 |
|
| 15 |
-
// Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
|
| 16 |
Mage::app()->setCurrentStore($store_id);
|
| 17 |
|
| 18 |
-
|
| 19 |
-
#echo "Running rs_send_users.php with arguments $store_id $timestamp $page_counter $last_user_record_id \n";
|
| 20 |
-
|
| 21 |
$observer = new RetentionScience_Waves_Model_Observer();
|
| 22 |
$elements_per_page = $observer->elementsPerPage();
|
| 23 |
|
|
|
|
| 24 |
$userCollection = Mage::getModel('customer/customer')->getCollection();
|
| 25 |
$userCollection->addAttributeToSelect('entity_id');
|
| 26 |
if($last_user_record_id>0){
|
| 27 |
-
|
| 28 |
}
|
| 29 |
-
|
| 30 |
$userCollection->setPage($page_counter, $elements_per_page);
|
| 31 |
|
| 32 |
try {
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
|
| 39 |
} catch (Exception $e){
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
}
|
| 44 |
|
| 1 |
<?php
|
| 2 |
+
// Generates all the users in a separate PHP process for memory efficiency
|
| 3 |
|
| 4 |
define('MAGENTO', realpath(dirname(__FILE__)));
|
| 5 |
require_once MAGENTO . '/../../../../../../app/Mage.php';
|
|
|
|
|
|
|
| 6 |
|
|
|
|
|
|
|
| 7 |
$store_id = $argv[1];
|
| 8 |
$timestamp = $argv[2];
|
| 9 |
$page_counter = $argv[3];
|
| 10 |
$last_user_record_id = $argv[4];
|
| 11 |
|
|
|
|
| 12 |
Mage::app()->setCurrentStore($store_id);
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
$observer = new RetentionScience_Waves_Model_Observer();
|
| 15 |
$elements_per_page = $observer->elementsPerPage();
|
| 16 |
|
| 17 |
+
// Retrieves the user collection
|
| 18 |
$userCollection = Mage::getModel('customer/customer')->getCollection();
|
| 19 |
$userCollection->addAttributeToSelect('entity_id');
|
| 20 |
if($last_user_record_id>0){
|
| 21 |
+
$userCollection->addFieldToFilter('entity_id', array('gt'=>$last_user_record_id));
|
| 22 |
}
|
|
|
|
| 23 |
$userCollection->setPage($page_counter, $elements_per_page);
|
| 24 |
|
| 25 |
try {
|
| 26 |
+
foreach($userCollection as $user){
|
| 27 |
+
$observer->userCallback(array('user_record_id' => $user->getEntityId(), 'timestamp' => $timestamp));
|
| 28 |
+
}
|
| 29 |
+
echo $observer->get_last_processed_user_entity_id();
|
| 30 |
+
die(0);
|
| 31 |
|
| 32 |
} catch (Exception $e){
|
| 33 |
+
Mage::logException($e);
|
| 34 |
+
echo $observer->get_last_processed_user_entity_id();
|
| 35 |
+
die(1);
|
| 36 |
}
|
| 37 |
|
app/code/community/RetentionScience/Waves/Model/rs_sync_data.php
CHANGED
|
@@ -1,9 +1,10 @@
|
|
| 1 |
<?php
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
define('MAGENTO', dirname(__FILE__));
|
| 4 |
require_once MAGENTO . '/../../../../../../app/Mage.php';
|
| 5 |
-
// require_once '/Applications/MAMP/htdocs/magento/app/Mage.php';
|
| 6 |
-
// require_once '/Users/-/Sites/magento/app/Mage.php';
|
| 7 |
|
| 8 |
$last_processed_order_record_id;
|
| 9 |
$last_processed_user_entity_id;
|
|
@@ -15,177 +16,177 @@ $observer = new RetentionScience_Waves_Model_Observer();
|
|
| 15 |
$phpBin = $observer->getPhpBin();
|
| 16 |
$elementsPerPage = $observer->elementsPerPage();
|
| 17 |
|
| 18 |
-
// Scripts
|
| 19 |
$send_orders_script = escapeshellarg(dirname(__FILE__) . "/rs_send_orders.php");
|
| 20 |
$send_products_script = escapeshellarg(dirname(__FILE__) . "/rs_send_products.php");
|
| 21 |
$send_users_script = escapeshellarg(dirname(__FILE__) . "/rs_send_users.php");
|
| 22 |
$rs_send_categories_script = escapeshellarg(dirname(__FILE__) . "/rs_send_categories.php");
|
| 23 |
$get_save_config_script = escapeshellarg(dirname(__FILE__) . "/rs_get_save_config.php");
|
| 24 |
|
| 25 |
-
// get / save
|
| 26 |
function getStoreConfig($key) {
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
}
|
| 36 |
|
| 37 |
function saveStoreConfig($key, $val) {
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
}
|
| 47 |
|
| 48 |
$syncDataStatus = getStoreConfig('waves/rs_sync_settings/sync_data_status');
|
|
|
|
| 49 |
if(stristr($syncDataStatus, "running")){
|
| 50 |
-
|
| 51 |
-
die(1);
|
| 52 |
}
|
| 53 |
|
| 54 |
// Perform all counts up front, so we don't need to make any further MySQL connections in this script
|
| 55 |
try {
|
| 56 |
-
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
|
| 81 |
|
| 82 |
} catch(Exception $e) {
|
| 83 |
-
|
| 84 |
-
|
| 85 |
}
|
| 86 |
|
| 87 |
// Export Orders
|
| 88 |
try{
|
| 89 |
-
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
|
| 111 |
} catch(Exception $e) {
|
| 112 |
-
|
| 113 |
-
|
| 114 |
}
|
| 115 |
|
| 116 |
// Export Users
|
| 117 |
try {
|
| 118 |
-
|
| 119 |
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
} catch (Exception $e){
|
| 138 |
-
|
| 139 |
-
|
| 140 |
}
|
| 141 |
|
| 142 |
// Export Products
|
| 143 |
try{
|
| 144 |
-
|
| 145 |
|
| 146 |
-
|
| 147 |
-
|
| 148 |
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
} catch (Exception $e){
|
| 161 |
-
|
| 162 |
-
|
| 163 |
}
|
| 164 |
|
| 165 |
// Export Categories
|
| 166 |
try {
|
| 167 |
-
|
| 168 |
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
|
| 178 |
} catch (Exception $e) {
|
| 179 |
-
|
| 180 |
-
|
| 181 |
}
|
| 182 |
|
| 183 |
-
// Send to
|
| 184 |
try {
|
| 185 |
-
|
| 186 |
} catch (Exception $e) {
|
| 187 |
-
|
| 188 |
-
|
| 189 |
}
|
| 190 |
|
| 191 |
// Update last exported IDs and status
|
| 1 |
<?php
|
| 2 |
+
// Runs the sync which will generate all the different file types.
|
| 3 |
+
// Each is done in a separate PHP process for memory efficiency when dealing with extremely large data exports
|
| 4 |
+
// This is much faster and memory efficient than running via 1 single process
|
| 5 |
|
| 6 |
define('MAGENTO', dirname(__FILE__));
|
| 7 |
require_once MAGENTO . '/../../../../../../app/Mage.php';
|
|
|
|
|
|
|
| 8 |
|
| 9 |
$last_processed_order_record_id;
|
| 10 |
$last_processed_user_entity_id;
|
| 16 |
$phpBin = $observer->getPhpBin();
|
| 17 |
$elementsPerPage = $observer->elementsPerPage();
|
| 18 |
|
| 19 |
+
// Scripts to export data
|
| 20 |
$send_orders_script = escapeshellarg(dirname(__FILE__) . "/rs_send_orders.php");
|
| 21 |
$send_products_script = escapeshellarg(dirname(__FILE__) . "/rs_send_products.php");
|
| 22 |
$send_users_script = escapeshellarg(dirname(__FILE__) . "/rs_send_users.php");
|
| 23 |
$rs_send_categories_script = escapeshellarg(dirname(__FILE__) . "/rs_send_categories.php");
|
| 24 |
$get_save_config_script = escapeshellarg(dirname(__FILE__) . "/rs_get_save_config.php");
|
| 25 |
|
| 26 |
+
// get / save functions to access the Magento config
|
| 27 |
function getStoreConfig($key) {
|
| 28 |
+
global $phpBin;
|
| 29 |
+
global $get_save_config_script;
|
| 30 |
+
global $store_id;
|
| 31 |
+
$output = array();
|
| 32 |
+
$return_val = null;
|
| 33 |
+
$cmd = "$phpBin $get_save_config_script $store_id GET '" . $key . "'";
|
| 34 |
+
exec($cmd, $output, $return_val);
|
| 35 |
+
return $output[0];
|
| 36 |
}
|
| 37 |
|
| 38 |
function saveStoreConfig($key, $val) {
|
| 39 |
+
global $phpBin;
|
| 40 |
+
global $get_save_config_script;
|
| 41 |
+
global $store_id;
|
| 42 |
+
$output = array();
|
| 43 |
+
$return_val = null;
|
| 44 |
+
$cmd = "$phpBin $get_save_config_script $store_id SAVE '" . $key . "' '" . $val . "'";
|
| 45 |
+
exec($cmd, $output, $return_val);
|
| 46 |
+
return $output[0];
|
| 47 |
}
|
| 48 |
|
| 49 |
$syncDataStatus = getStoreConfig('waves/rs_sync_settings/sync_data_status');
|
| 50 |
+
// If it's already running, just exit
|
| 51 |
if(stristr($syncDataStatus, "running")){
|
| 52 |
+
die(1);
|
|
|
|
| 53 |
}
|
| 54 |
|
| 55 |
// Perform all counts up front, so we don't need to make any further MySQL connections in this script
|
| 56 |
try {
|
| 57 |
+
saveStoreConfig('waves/rs_sync_settings/sync_data_status', '[running] Calculating counts at: ' . date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time())));
|
| 58 |
|
| 59 |
+
// Count Orders
|
| 60 |
+
$last_order_record_id = (int) getStoreConfig('waves/rs_sync_advanced/last_order_record_id');
|
| 61 |
+
$orderCollection = Mage::getModel('sales/order')->getCollection();
|
| 62 |
+
if($last_order_record_id>0){
|
| 63 |
+
$orderCollection->addFieldToFilter('entity_id', array('gt' => $last_order_record_id));
|
| 64 |
+
}
|
| 65 |
+
$num_orders_to_send = $orderCollection->getSize(); // Don't use count()
|
| 66 |
|
| 67 |
+
// Count Users
|
| 68 |
+
$last_user_record_id = (int) getStoreConfig('waves/rs_sync_advanced/last_user_record_id');
|
| 69 |
+
$userCollection = Mage::getModel('customer/customer')
|
| 70 |
+
->getCollection()
|
| 71 |
+
->addAttributeToSelect('name')
|
| 72 |
+
->addAttributeToSelect('*');
|
| 73 |
+
if($last_user_record_id>0){
|
| 74 |
+
$userCollection->addFieldToFilter('entity_id', array('gt' => $last_user_record_id));
|
| 75 |
+
}
|
| 76 |
+
$num_users_to_send = $userCollection->getSize(); // Don't use count()
|
| 77 |
|
| 78 |
+
// Count Products
|
| 79 |
+
$productCollection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
|
| 80 |
+
$num_products_to_send = $productCollection->getSize();
|
| 81 |
|
| 82 |
|
| 83 |
} catch(Exception $e) {
|
| 84 |
+
Mage::logException($e);
|
| 85 |
+
saveStoreConfig('waves/rs_sync_settings/sync_data_status', '[stopped] error performing counts at: ' . date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time())));
|
| 86 |
}
|
| 87 |
|
| 88 |
// Export Orders
|
| 89 |
try{
|
| 90 |
+
saveStoreConfig('waves/rs_sync_settings/sync_data_status', '[running] exporting orders - last updated at: ' . date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time())));
|
| 91 |
|
| 92 |
+
// this will be updated as we iterate
|
| 93 |
+
$last_processed_order_record_id = $last_order_record_id;
|
| 94 |
|
| 95 |
+
$pages = ceil($num_orders_to_send / $elementsPerPage);
|
| 96 |
+
$page_counter = 1;
|
| 97 |
|
| 98 |
+
while($page_counter <= $pages){
|
| 99 |
+
$cmd = "$phpBin $send_orders_script $store_id $timestamp $page_counter $last_order_record_id";
|
| 100 |
+
$output = array();
|
| 101 |
+
$return_val = null;
|
| 102 |
+
exec($cmd, $output, $return_val);
|
| 103 |
+
if ($return_val != 0){
|
| 104 |
+
var_dump($output);
|
| 105 |
+
throw new Exception('Send orders script returned with non-zero return code.');
|
| 106 |
+
} else {
|
| 107 |
+
$last_processed_order_record_id = $output[0];
|
| 108 |
+
}
|
| 109 |
+
$page_counter = $page_counter + 1;
|
| 110 |
+
}
|
| 111 |
|
| 112 |
} catch(Exception $e) {
|
| 113 |
+
Mage::logException($e);
|
| 114 |
+
saveStoreConfig('waves/rs_sync_settings/sync_data_status', '[stopped] error on orders at: ' . date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time())));
|
| 115 |
}
|
| 116 |
|
| 117 |
// Export Users
|
| 118 |
try {
|
| 119 |
+
saveStoreConfig('waves/rs_sync_settings/sync_data_status', '[running] exporting users - last updated at: ' . date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time())));
|
| 120 |
|
| 121 |
|
| 122 |
+
$pages = ceil($num_users_to_send / $elementsPerPage);
|
| 123 |
+
$page_counter = 1;
|
| 124 |
|
| 125 |
+
while($page_counter <= $pages){
|
| 126 |
+
$cmd = "$phpBin $send_users_script $store_id $timestamp $page_counter $last_user_record_id";
|
| 127 |
+
$output = array();
|
| 128 |
+
$return_val = null;
|
| 129 |
+
exec($cmd, $output, $return_val);
|
| 130 |
+
if ($return_val != 0){
|
| 131 |
+
var_dump($output);
|
| 132 |
+
throw new Exception('Send users script returned with non-zero return code.');
|
| 133 |
+
} else {
|
| 134 |
+
$last_processed_user_record_id = $output[0];
|
| 135 |
+
}
|
| 136 |
+
$page_counter = $page_counter + 1;
|
| 137 |
+
}
|
| 138 |
} catch (Exception $e){
|
| 139 |
+
Mage::logException($e);
|
| 140 |
+
saveStoreConfig('waves/rs_sync_settings/sync_data_status', '[stopped] error on users at: ' . date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time())));
|
| 141 |
}
|
| 142 |
|
| 143 |
// Export Products
|
| 144 |
try{
|
| 145 |
+
saveStoreConfig('waves/rs_sync_settings/sync_data_status', '[running] exporting products - last updated at: ' . date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time())));
|
| 146 |
|
| 147 |
+
$pages = ceil($num_products_to_send / $elementsPerPage);
|
| 148 |
+
$page_counter = 1;
|
| 149 |
|
| 150 |
+
while($page_counter <= $pages){
|
| 151 |
+
$cmd = "$phpBin $send_products_script $store_id $timestamp $page_counter";
|
| 152 |
+
$output = array();
|
| 153 |
+
$return_val = null;
|
| 154 |
+
exec($cmd, $output, $return_val);
|
| 155 |
+
if ($return_val != 0){
|
| 156 |
+
var_dump($output);
|
| 157 |
+
throw new Exception('Send products script returned with non-zero return code.');
|
| 158 |
+
}
|
| 159 |
+
$page_counter = $page_counter + 1;
|
| 160 |
+
}
|
| 161 |
} catch (Exception $e){
|
| 162 |
+
Mage::logException($e);
|
| 163 |
+
saveStoreConfig('waves/rs_sync_settings/sync_data_status', '[stopped] error on products at: ' . date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time())));
|
| 164 |
}
|
| 165 |
|
| 166 |
// Export Categories
|
| 167 |
try {
|
| 168 |
+
saveStoreConfig('waves/rs_sync_settings/sync_data_status', '[running] exporting categories - last updated at: ' . date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time())));
|
| 169 |
|
| 170 |
+
$output = array();
|
| 171 |
+
$return_val = null;
|
| 172 |
+
$cmd = "$phpBin $rs_send_categories_script $store_id $timestamp";
|
| 173 |
+
exec($cmd, $output, $return_val);
|
| 174 |
+
if ($return_val != 0){
|
| 175 |
+
var_dump($output);
|
| 176 |
+
throw new Exception('Send categories script returned with non-zero return code.');
|
| 177 |
+
}
|
| 178 |
|
| 179 |
} catch (Exception $e) {
|
| 180 |
+
Mage::logException($e);
|
| 181 |
+
saveStoreConfig('waves/rs_sync_settings/sync_data_status', '[stopped] error on categories at: ' . date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time())) );
|
| 182 |
}
|
| 183 |
|
| 184 |
+
// Send to rs api
|
| 185 |
try {
|
| 186 |
+
$observer->sendDataSyncFiles($timestamp);
|
| 187 |
} catch (Exception $e) {
|
| 188 |
+
Mage::logException($e);
|
| 189 |
+
saveStoreConfig('waves/rs_sync_settings/sync_data_status', '[stopped] error on upload at: ' . date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time())) );
|
| 190 |
}
|
| 191 |
|
| 192 |
// Update last exported IDs and status
|
app/code/community/RetentionScience/Waves/controllers/AdminController.php
CHANGED
|
@@ -1,15 +1,15 @@
|
|
| 1 |
<?php
|
| 2 |
class RetentionScience_Waves_AdminController extends Mage_Adminhtml_Controller_Action
|
| 3 |
{
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
}
|
| 1 |
<?php
|
| 2 |
class RetentionScience_Waves_AdminController extends Mage_Adminhtml_Controller_Action
|
| 3 |
{
|
| 4 |
+
public function updateRScoreAction() {
|
| 5 |
+
$obj = new RetentionScience_Waves_Model_Observer();
|
| 6 |
+
$rscore_json = $obj->updateRScore();
|
| 7 |
+
die($rscore_json);
|
| 8 |
+
}
|
| 9 |
|
| 10 |
+
public function syncDataAction() {
|
| 11 |
+
$obj = new RetentionScience_Waves_Model_Observer();
|
| 12 |
+
$obj->syncData();
|
| 13 |
+
$this->_redirectUrl(Mage::helper('adminhtml')->getUrl("adminhtml/system_config/edit/section/waves/"));
|
| 14 |
+
}
|
| 15 |
}
|
app/code/community/RetentionScience/Waves/controllers/IndexController.php
CHANGED
|
@@ -1,31 +1,31 @@
|
|
| 1 |
<?php
|
| 2 |
class RetentionScience_Waves_IndexController extends Mage_Core_Controller_Front_Action
|
| 3 |
{
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
}
|
| 1 |
<?php
|
| 2 |
class RetentionScience_Waves_IndexController extends Mage_Core_Controller_Front_Action
|
| 3 |
{
|
| 4 |
+
public function scriptRunAction(){
|
| 5 |
+
$status = Mage::getStoreConfig('waves/retentionscience_settings/enable');
|
| 6 |
+
$siteID = Mage::getStoreConfig('waves/retentionscience_settings/site_id');
|
| 7 |
+
if($status && $siteID){
|
| 8 |
|
| 9 |
+
$result['siteID'] = $siteID;
|
| 10 |
+
$result['customerId'] = "";
|
| 11 |
+
if(Mage::getSingleton('customer/session')->isLoggedIn()){
|
| 12 |
+
$customerId = Mage::getSingleton('customer/session')->getCustomerId();
|
| 13 |
+
$result['customerId'] = $customerId;
|
| 14 |
+
}
|
| 15 |
|
| 16 |
|
| 17 |
+
$allItems = Mage::getModel('checkout/cart')->getQuote()->getAllItems();
|
| 18 |
+
$items = array();
|
| 19 |
+
$count = 0;
|
| 20 |
+
foreach ($allItems as $item){
|
| 21 |
+
$items[$count]['id'] = $item->getProductId();
|
| 22 |
+
$items[$count]['name'] = $item->getName();
|
| 23 |
+
$items[$count]['price'] = $item->getPrice();
|
| 24 |
+
$count++;
|
| 25 |
+
}
|
| 26 |
+
$result['items'] = json_encode($items);
|
| 27 |
+
echo json_encode($result);
|
| 28 |
+
die();
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
}
|
app/code/community/RetentionScience/Waves/etc/config.xml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
<config>
|
| 3 |
<modules>
|
| 4 |
<RetentionScience_Waves>
|
| 5 |
-
<version>2.1.
|
| 6 |
</RetentionScience_Waves>
|
| 7 |
</modules>
|
| 8 |
<global>
|
|
@@ -72,7 +72,6 @@
|
|
| 72 |
<rs_sync_advanced>
|
| 73 |
<rs_php_bin>php</rs_php_bin>
|
| 74 |
<rs_send_bulk_upload>1</rs_send_bulk_upload>
|
| 75 |
-
<rs_bulk_use_exec>1</rs_bulk_use_exec>
|
| 76 |
<last_user_record_id>0</last_user_record_id>
|
| 77 |
<last_order_record_id>0</last_order_record_id>
|
| 78 |
</rs_sync_advanced>
|
| 2 |
<config>
|
| 3 |
<modules>
|
| 4 |
<RetentionScience_Waves>
|
| 5 |
+
<version>2.1.8</version>
|
| 6 |
</RetentionScience_Waves>
|
| 7 |
</modules>
|
| 8 |
<global>
|
| 72 |
<rs_sync_advanced>
|
| 73 |
<rs_php_bin>php</rs_php_bin>
|
| 74 |
<rs_send_bulk_upload>1</rs_send_bulk_upload>
|
|
|
|
| 75 |
<last_user_record_id>0</last_user_record_id>
|
| 76 |
<last_order_record_id>0</last_order_record_id>
|
| 77 |
</rs_sync_advanced>
|
app/code/community/RetentionScience/Waves/etc/system.xml
CHANGED
|
@@ -180,16 +180,6 @@
|
|
| 180 |
<show_in_website>1</show_in_website>
|
| 181 |
<show_in_store>1</show_in_store>
|
| 182 |
</rs_use_bulk_compression>
|
| 183 |
-
|
| 184 |
-
<rs_bulk_use_exec translate="label">
|
| 185 |
-
<label>Use PHP exec() to save memory</label>
|
| 186 |
-
<frontend_type>select</frontend_type>
|
| 187 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 188 |
-
<sort_order>98</sort_order>
|
| 189 |
-
<show_in_default>1</show_in_default>
|
| 190 |
-
<show_in_website>1</show_in_website>
|
| 191 |
-
<show_in_store>1</show_in_store>
|
| 192 |
-
</rs_bulk_use_exec>
|
| 193 |
|
| 194 |
<last_user_record_id translate="label">
|
| 195 |
<label>Last sync'd user record id</label>
|
| 180 |
<show_in_website>1</show_in_website>
|
| 181 |
<show_in_store>1</show_in_store>
|
| 182 |
</rs_use_bulk_compression>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
<last_user_record_id translate="label">
|
| 185 |
<label>Last sync'd user record id</label>
|
app/design/frontend/base/default/template/waves/waves.phtml
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
<?php
|
| 2 |
$status = $this->isEnable();
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
| 10 |
<!-- lmca <?php echo $loggedIn ?> | <?php echo $moduleName ?> | <?php echo $controllerName ?> | <?php echo $actionName ?> -->
|
| 11 |
|
| 12 |
|
|
@@ -74,6 +74,6 @@ $status = $this->isEnable();
|
|
| 74 |
<script type="text/javascript">
|
| 75 |
setAjaxSendCartUrl('<?php echo Mage::getUrl('waves/index/scriptRun') ?>');
|
| 76 |
</script>
|
| 77 |
-
|
| 78 |
-
|
| 79 |
?>
|
| 1 |
<?php
|
| 2 |
$status = $this->isEnable();
|
| 3 |
+
if($status && $this->getSiteid()){
|
| 4 |
+
$loggedIn = $this->customerLoggedIn();
|
| 5 |
+
$moduleName = $this->getRequest()->getModuleName();
|
| 6 |
+
$controllerName = $this->getRequest()->getControllerName();
|
| 7 |
+
$actionName = $this->getRequest()->getActionName();
|
| 8 |
|
| 9 |
+
?>
|
| 10 |
<!-- lmca <?php echo $loggedIn ?> | <?php echo $moduleName ?> | <?php echo $controllerName ?> | <?php echo $actionName ?> -->
|
| 11 |
|
| 12 |
|
| 74 |
<script type="text/javascript">
|
| 75 |
setAjaxSendCartUrl('<?php echo Mage::getUrl('waves/index/scriptRun') ?>');
|
| 76 |
</script>
|
| 77 |
+
<?php }
|
| 78 |
+
}
|
| 79 |
?>
|
js/RetentionScience/retention_science_wave.js
CHANGED
|
@@ -1,38 +1,37 @@
|
|
| 1 |
var rSciUrl = "";
|
| 2 |
function setAjaxSendCartUrl(ajax_send_cart_url){
|
| 3 |
-
|
| 4 |
}
|
| 5 |
|
| 6 |
function retention_science_send_cart(){
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
};
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
}
|
| 1 |
var rSciUrl = "";
|
| 2 |
function setAjaxSendCartUrl(ajax_send_cart_url){
|
| 3 |
+
rSciUrl = ajax_send_cart_url;
|
| 4 |
}
|
| 5 |
|
| 6 |
function retention_science_send_cart(){
|
| 7 |
+
if(rSciUrl!=""){
|
| 8 |
+
new Ajax.Request(rSciUrl, {
|
| 9 |
+
onSuccess: function(transport) {
|
| 10 |
|
| 11 |
+
var json = transport.responseText.evalJSON();
|
| 12 |
+
siteID = json.siteID;
|
| 13 |
|
| 14 |
+
rsci_init = function(){
|
| 15 |
+
rsci_wave.set_site_id(siteID);
|
| 16 |
+
rsci_wave.set_action('shopping_cart');
|
| 17 |
|
| 18 |
+
if(json.customerId!=""){
|
| 19 |
+
rsci_wave.set_user_id(json.customerId);
|
| 20 |
+
}
|
| 21 |
|
| 22 |
+
items = json.items.evalJSON();
|
| 23 |
+
items.each(function(item){
|
| 24 |
+
var data = {id:item.id, name:item.name, price:item.price };
|
| 25 |
+
rsci_wave.add_item(data);
|
| 26 |
+
});
|
| 27 |
+
};
|
|
|
|
| 28 |
|
| 29 |
+
(function() { var iBx = document.createElement('script'); iBx.type = 'text/javascript'; iBx.async =
|
| 30 |
+
true; iBx.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'waves.retentionscience.com/w.js';
|
| 31 |
+
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(iBx); })();
|
| 32 |
|
| 33 |
+
//rsci_init();
|
| 34 |
+
}, method: "get"
|
| 35 |
+
});
|
| 36 |
+
}
|
| 37 |
}
|
package.xml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>RetentionScience_Waves</name>
|
| 4 |
-
<version>2.1.
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license uri="http://www.apache.org/licenses/LICENSE-2.0.html">Apache License 2.0</license>
|
| 7 |
<channel>community</channel>
|
|
@@ -16,11 +16,11 @@ We leverage big data analytics and machine learning to optimize retention strate
|
|
| 16 |
Our technology enables your store to leverage massive social media, demographic, and behavioral datasets - powerful information sources to help you drive sales. 
|
| 17 |

|
| 18 |
Notes: This extension interfaces with Retention Science, and communicates through the Retention Science API. For more information, and to sign up for API access, please see http://retentionscience.com.</description>
|
| 19 |
-
<notes>
|
| 20 |
<authors><author><name>Retention Science</name><user>auto-converted</user><email>support@retentionscience.com</email></author></authors>
|
| 21 |
-
<date>2013-
|
| 22 |
-
<time>
|
| 23 |
-
<contents><target name="magecommunity"><dir name="RetentionScience"><dir name="Waves"><dir name="Block"><dir name="Adminhtml"><file name="Rscore.php" hash="ddaa6fcc9b7c7448ca4546e28ded58f3"/><file name="Syncbutton.php" hash="
|
| 24 |
<compatible/>
|
| 25 |
<dependencies/>
|
| 26 |
</package>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>RetentionScience_Waves</name>
|
| 4 |
+
<version>2.1.8</version>
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license uri="http://www.apache.org/licenses/LICENSE-2.0.html">Apache License 2.0</license>
|
| 7 |
<channel>community</channel>
|
| 16 |
Our technology enables your store to leverage massive social media, demographic, and behavioral datasets - powerful information sources to help you drive sales. 
|
| 17 |

|
| 18 |
Notes: This extension interfaces with Retention Science, and communicates through the Retention Science API. For more information, and to sign up for API access, please see http://retentionscience.com.</description>
|
| 19 |
+
<notes>Formatting updated</notes>
|
| 20 |
<authors><author><name>Retention Science</name><user>auto-converted</user><email>support@retentionscience.com</email></author></authors>
|
| 21 |
+
<date>2013-06-09</date>
|
| 22 |
+
<time>06:16:47</time>
|
| 23 |
+
<contents><target name="magecommunity"><dir name="RetentionScience"><dir name="Waves"><dir name="Block"><dir name="Adminhtml"><file name="Rscore.php" hash="ddaa6fcc9b7c7448ca4546e28ded58f3"/><file name="Syncbutton.php" hash="f0e364d31e12bffd40a13e88bce3bc97"/></dir><file name="Waves.php" hash="e40dffc0ab52847e560182196a252291"/></dir><dir name="Helper"><file name="Data.php" hash="90490af254a670d4795b744c1ef4319e"/><file name="Storeselect.php" hash="dbfeb7a4e9e1f5c52fdbc2eac9370fcf"/></dir><dir name="Model"><dir name="Source"><dir name="Cron"><file name="Frequency.php" hash="027feb7796f79b7cf811c4236ad7b87a"/><file name="Hours.php" hash="0ab9157003d5e7efed402ed401a46134"/></dir><file name="Categorytree.php" hash="8911fb34a76fed31b9e20a6a9fea0712"/><file name="Cronconfig.php" hash="f2dd3dcd572bd7407663576e250f9d23"/><file name="Rscoredata.php" hash="178f70a1f05415c86b6c5e959fb2fe50"/></dir><file name="Observer.php" hash="bdf08ae6ff20ba85878ca8e368cd9c1a"/><file name="retention_science_api.php" hash="d9d5197492408502cf6084f19def5aa0"/><file name="rs_get_save_config.php" hash="9ff13acecc3cc89066e1476ee48459fb"/><file name="rs_send_categories.php" hash="1633b1c1b01a9c3666c0687586693102"/><file name="rs_send_orders.php" hash="1b4f0260e74fbe11436af16238ecd61b"/><file name="rs_send_products.php" hash="c54656d728ad1c91185be35dd27f86d2"/><file name="rs_send_users.php" hash="0e27f4293d666c35e90ebb852ae83fb7"/><file name="rs_sync_data.php" hash="5b7ed9f5e50e26b343cae9578bf053bd"/></dir><dir name="controllers"><file name="AdminController.php" hash="25905c7233adde08763a74d8792e722f"/><file name="IndexController.php" hash="281b3223e4b71858ec0b43739bcdf97d"/></dir><dir name="etc"><file name="adminhtml.xml" hash="1378650fdb7ecc596f9881d7eefca868"/><file name="config.xml" hash="2928a41064b3a8a3b084306c054d73c2"/><file name="system.xml" hash="b2d00b02e576c1ee4049951577d74610"/></dir></dir><file name=".DS_Store" hash="128e595394427daa0503e6d824d6b4ef"/></dir></target><target name="mageweb"><dir name="js"><dir name="RetentionScience"><file name="retention_science_wave.js" hash="10bb411288770c07290c693ac03700b6"/></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="waves.xml" hash="7f62bec7d87da48c0e554fc1cf3a9802"/></dir><dir name="template"><dir name="waves"><file name="waves.phtml" hash="c68251968b899428356f743a92b0ce9f"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="waves"><file name="rscore.phtml" hash="4f6af3dd918b23a009bb559e12f23c05"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="RetentionScience_Waves.xml" hash="9dc27ff12e5834f576b22a72a60d02e7"/></dir></target></contents>
|
| 24 |
<compatible/>
|
| 25 |
<dependencies/>
|
| 26 |
</package>
|
