Version Notes
faster import
Download this release
Release Info
| Developer | Moshe |
| Extension | Wisepricer_Syncer |
| Version | 1.1.2.9 |
| Comparing to | |
| See all releases | |
Code changes from version 1.1.2.8 to 1.1.2.9
app/code/local/Wisepricer/Syncer/controllers/ProductsController.php
CHANGED
|
@@ -1,56 +1,60 @@
|
|
| 1 |
<?php
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
class Wisepricer_Syncer_ProductsController extends Mage_Core_Controller_Front_Action
|
| 7 |
{
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
set_time_limit (1800);
|
| 14 |
$licenseData =Mage::getModel('wisepricer_syncer/config')->load(1);
|
| 15 |
if(!$licenseData->getData()||$licenseData->getIs_confirmed()==0){
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
}
|
| 25 |
-
|
| 26 |
$post = $this->getRequest()->getParams();
|
| 27 |
-
|
| 28 |
$magentoSessionId=Mage::getModel('core/cookie')->get('wpsession');
|
| 29 |
-
|
| 30 |
if($magentoSessionId!=$post['sesssionid']){
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
}
|
| 40 |
-
|
| 41 |
-
|
| 42 |
$startInd = $post['start'];
|
| 43 |
if(!$startInd){
|
| 44 |
-
|
| 45 |
}
|
| 46 |
-
|
| 47 |
$count = $post['count'];
|
| 48 |
if(!$count||$count>200){
|
| 49 |
-
|
| 50 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
$fieldsEncoded= $post['params'];
|
| 52 |
$fields =json_decode(urldecode ($fieldsEncoded));
|
| 53 |
-
|
| 54 |
$mappings =Mage::getModel('wisepricer_syncer/mapping')->getCollection()->getData();
|
| 55 |
|
| 56 |
$collection=Mage::getModel('catalog/product')->getCollection();
|
|
@@ -58,152 +62,157 @@ class Wisepricer_Syncer_ProductsController extends Mage_Core_Controller_Front_Ac
|
|
| 58 |
$requiredFields=array();
|
| 59 |
foreach ($mappings as $fieldsArr) {
|
| 60 |
if($fields[0]=='all'||in_array($fieldsArr['wsp_field'],$fields)){
|
| 61 |
-
|
| 62 |
}
|
| 63 |
-
|
| 64 |
if(!is_numeric($fieldsArr['magento_field'])){
|
| 65 |
-
|
| 66 |
}
|
| 67 |
-
|
| 68 |
-
}
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
$productsOutput=array();
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
foreach ($collection as $product) {
|
| 76 |
-
// echo '<pre>'.print_r($product->getData(),true).'</pre>';die;
|
| 77 |
$productCollData=$product->getData();
|
| 78 |
$productModel=Mage::getModel('catalog/product')->load($productCollData['entity_id']);
|
| 79 |
-
|
| 80 |
-
//TODO add user control here - dont bring not saleble products
|
| 81 |
-
if(!$productModel->isSaleable()){
|
| 82 |
-
continue;
|
| 83 |
-
}
|
| 84 |
$this->productOrigData=$productModel->getData();
|
| 85 |
$productData=array();
|
| 86 |
-
|
| 87 |
foreach ($requiredFields as $field) {
|
|
|
|
| 88 |
if($field['wsp_field']=='stock'){
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
}elseif($field['wsp_field']=='productimage'){
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
}elseif($field['wsp_field']=='shipping'){
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
| 112 |
}elseif($field['wsp_field']=='minprice'){
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
| 121 |
}else{
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
}
|
| 138 |
-
|
| 139 |
|
| 140 |
}
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
$productsOutput[]=$productData;
|
| 145 |
}
|
| 146 |
-
|
| 147 |
-
// echo '<pre>'.print_r($productsOutput,true).'</pre>'; die;
|
| 148 |
$returnArr=array(
|
| 149 |
'status'=>'success',
|
| 150 |
'error_code'=>'0',
|
| 151 |
'data'=>$productsOutput
|
| 152 |
);
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
| 162 |
if($ruleArr[1]=='a'){
|
| 163 |
$costField=$this->_getMagentoFieldByWsField('cost');
|
| 164 |
if($costField){
|
| 165 |
$cost=$this->productOrigData[$costField];
|
| 166 |
if($ruleArr[0]=='-1'){
|
| 167 |
-
$minPrice=($cost*$field['magento_field'])/100+$cost;
|
| 168 |
}else{
|
| 169 |
-
$minPrice=$cost+$field['magento_field'];
|
| 170 |
}
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
$model = Mage::getModel('wisepricer_syncer/mapping');
|
| 188 |
$mappingId=$model->loadIdByWsfield($wsfield);
|
| 189 |
if($mappingId){
|
| 190 |
$mapping=$model->load($mappingId);
|
| 191 |
return $mapping->getmagento_field();
|
| 192 |
-
}
|
| 193 |
-
|
| 194 |
return false;
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
|
| 208 |
public function loginAction(){
|
| 209 |
|
|
@@ -251,36 +260,36 @@ class Wisepricer_Syncer_ProductsController extends Mage_Core_Controller_Front_Ac
|
|
| 251 |
Mage::log(print_r('=========================================================',true),null,'wplog.log');
|
| 252 |
echo json_encode($returnArr);
|
| 253 |
}
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
$post = $this->getRequest()->getParams();
|
| 258 |
-
|
| 259 |
$magentoSessionId=Mage::getModel('core/cookie')->get('wpsession');
|
| 260 |
-
|
| 261 |
if($magentoSessionId!=$post['sesssionid']){
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
}
|
| 271 |
-
|
| 272 |
-
Mage::getModel('core/cookie')->delete('wpsession');
|
| 273 |
$returnArr=array(
|
| 274 |
'status'=>'success',
|
| 275 |
'error_code'=>'0'
|
| 276 |
);
|
| 277 |
|
| 278 |
echo json_encode($returnArr);
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
$returnArr=array(
|
| 285 |
'status'=>'success',
|
| 286 |
'error_code'=>'0',
|
|
@@ -288,186 +297,193 @@ class Wisepricer_Syncer_ProductsController extends Mage_Core_Controller_Front_Ac
|
|
| 288 |
);
|
| 289 |
|
| 290 |
echo json_encode($returnArr);
|
| 291 |
-
|
| 292 |
-
|
| 293 |
protected function _getprivatekey(){
|
| 294 |
-
|
| 295 |
-
|
| 296 |
if(!$licenseData->getData()||$licenseData->getIs_confirmed()==0){
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
}
|
| 306 |
-
|
| 307 |
return $licenseData->getprivatekey();
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
if(!$licenseData->getData()||$licenseData->getIs_confirmed()==0){
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
}
|
| 323 |
-
|
| 324 |
return $licenseData->getpublickey();
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
Mage::log(print_r('Entered reprice action',true),null,'wplog.log');
|
| 339 |
set_time_limit (1800);
|
| 340 |
$licenseData =Mage::getModel('wisepricer_syncer/config')->load(1);
|
| 341 |
if(!$licenseData->getData()||$licenseData->getIs_confirmed()==0){
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
}
|
| 351 |
-
|
| 352 |
$post = $this->getRequest()->getParams();
|
| 353 |
-
|
| 354 |
$magentoSessionId=Mage::getModel('core/cookie')->get('wpsession');
|
| 355 |
Mage::log(print_r('Received session'.$post['sesssionid'],true),null,'wplog.log');
|
| 356 |
-
Mage::log(print_r('Stored session'.$magentoSessionId,true),null,'wplog.log');
|
| 357 |
if($magentoSessionId!=$post['sesssionid']){
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
}
|
| 367 |
-
|
| 368 |
$productsEncoded= $post['products'];
|
| 369 |
$products =json_decode(urldecode ($productsEncoded));
|
| 370 |
$responseArr=array();
|
| 371 |
$sucessCounter=0;
|
| 372 |
$failedCounter=0;
|
| 373 |
-
Mage::log(print_r('repricing '.count($products),true),null,'wplog.log');
|
| 374 |
-
$repriceModel=Mage::getModel('wisepricer_syncer/reprice');
|
| 375 |
-
|
| 376 |
foreach ($products as $prodArr) {
|
| 377 |
-
|
| 378 |
if ($repriceModel->checkIfSkuExists($prodArr->sku)) {
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
}else{
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
}
|
| 394 |
-
|
| 395 |
-
|
| 396 |
}
|
| 397 |
-
|
| 398 |
-
|
| 399 |
$error_code=-1;
|
| 400 |
$error_details='Magento could not update any product.';
|
| 401 |
-
|
| 402 |
$error_code=0;
|
| 403 |
$error_details='';
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
Mage::log(print_r('Entered reindex action',true),null,'wplog.log');
|
| 419 |
|
| 420 |
$licenseData =Mage::getModel('wisepricer_syncer/config')->load(1);
|
| 421 |
if(!$licenseData->getData()||$licenseData->getIs_confirmed()==0){
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
}
|
| 431 |
-
|
| 432 |
$post = $this->getRequest()->getParams();
|
| 433 |
-
|
| 434 |
$magentoSessionId=Mage::getModel('core/cookie')->get('wpsession');
|
| 435 |
//Mage::log(print_r('Received session'.$post['sesssionid'],true),null,'wplog.log');
|
| 436 |
//Mage::log(print_r('Stored session'.$magentoSessionId,true),null,'wplog.log');
|
| 437 |
if($magentoSessionId!=$post['sesssionid']){
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
}
|
| 447 |
Mage::getSingleton('index/indexer')->getProcessByCode('catalog_product_price')->reindexAll();
|
| 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 |
?>
|
| 1 |
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Performs integration between Wisepricer and Magento
|
| 4 |
+
*
|
| 5 |
+
*/
|
| 6 |
class Wisepricer_Syncer_ProductsController extends Mage_Core_Controller_Front_Action
|
| 7 |
{
|
| 8 |
+
|
| 9 |
+
private $productOrigData=array();
|
| 10 |
+
|
| 11 |
+
public function sendAction(){
|
| 12 |
+
// Mage::log('start sending',null,'wplog.log');
|
| 13 |
set_time_limit (1800);
|
| 14 |
$licenseData =Mage::getModel('wisepricer_syncer/config')->load(1);
|
| 15 |
if(!$licenseData->getData()||$licenseData->getIs_confirmed()==0){
|
| 16 |
+
|
| 17 |
+
$returnArr=array(
|
| 18 |
+
'status'=>'failure',
|
| 19 |
+
'error_code'=>'769',
|
| 20 |
+
'error_details'=>'The user has not completed the integration.'
|
| 21 |
+
);
|
| 22 |
+
echo json_encode($returnArr);
|
| 23 |
+
die;
|
| 24 |
}
|
| 25 |
+
|
| 26 |
$post = $this->getRequest()->getParams();
|
| 27 |
+
|
| 28 |
$magentoSessionId=Mage::getModel('core/cookie')->get('wpsession');
|
| 29 |
+
|
| 30 |
if($magentoSessionId!=$post['sesssionid']){
|
| 31 |
+
|
| 32 |
+
$returnArr=array(
|
| 33 |
+
'status'=>'failure',
|
| 34 |
+
'error_code'=>'771',
|
| 35 |
+
'error_details'=>'Unauthorized access.'
|
| 36 |
+
);
|
| 37 |
+
echo json_encode($returnArr);
|
| 38 |
+
die;
|
| 39 |
}
|
| 40 |
+
|
| 41 |
+
|
| 42 |
$startInd = $post['start'];
|
| 43 |
if(!$startInd){
|
| 44 |
+
$startInd=0;
|
| 45 |
}
|
| 46 |
+
|
| 47 |
$count = $post['count'];
|
| 48 |
if(!$count||$count>200){
|
| 49 |
+
$count=200;
|
| 50 |
}
|
| 51 |
+
|
| 52 |
+
$pageNum=($startInd/$count)+1;
|
| 53 |
+
|
| 54 |
+
|
| 55 |
$fieldsEncoded= $post['params'];
|
| 56 |
$fields =json_decode(urldecode ($fieldsEncoded));
|
| 57 |
+
|
| 58 |
$mappings =Mage::getModel('wisepricer_syncer/mapping')->getCollection()->getData();
|
| 59 |
|
| 60 |
$collection=Mage::getModel('catalog/product')->getCollection();
|
| 62 |
$requiredFields=array();
|
| 63 |
foreach ($mappings as $fieldsArr) {
|
| 64 |
if($fields[0]=='all'||in_array($fieldsArr['wsp_field'],$fields)){
|
| 65 |
+
$requiredFields[]=$fieldsArr;
|
| 66 |
}
|
| 67 |
+
|
| 68 |
if(!is_numeric($fieldsArr['magento_field'])){
|
| 69 |
+
$collection->addAttributeToSelect($fieldsArr['magento_field']);
|
| 70 |
}
|
| 71 |
+
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
//TODO add user control here - dont bring not saleble products
|
| 75 |
+
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
|
| 76 |
+
$collection->setPage($pageNum, $count)->load();
|
| 77 |
+
// echo '<pre>'.print_r($collection->getData(),true).'</pre>'; die;
|
| 78 |
|
| 79 |
$productsOutput=array();
|
| 80 |
|
| 81 |
+
|
| 82 |
+
|
| 83 |
foreach ($collection as $product) {
|
|
|
|
| 84 |
$productCollData=$product->getData();
|
| 85 |
$productModel=Mage::getModel('catalog/product')->load($productCollData['entity_id']);
|
| 86 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
$this->productOrigData=$productModel->getData();
|
| 88 |
$productData=array();
|
| 89 |
+
|
| 90 |
foreach ($requiredFields as $field) {
|
| 91 |
+
|
| 92 |
if($field['wsp_field']=='stock'){
|
| 93 |
+
|
| 94 |
+
$qtyStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();
|
| 95 |
+
$productData['stock']=(int)$qtyStock;
|
| 96 |
+
|
| 97 |
}elseif($field['wsp_field']=='productimage'){
|
| 98 |
+
|
| 99 |
+
if($field['magento_field']=='image'||$field['magento_field']=='small_image'){
|
| 100 |
+
$siteUrl=substr_replace(Mage::getUrl('media/catalog/product') ,"",-1);
|
| 101 |
+
$productData['productimage']=$siteUrl.$this->productOrigData['image'];
|
| 102 |
+
}else{
|
| 103 |
+
$productData['productimage']=$this->productOrigData['image'];
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
|
| 107 |
}elseif($field['wsp_field']=='shipping'){
|
| 108 |
+
|
| 109 |
+
if(is_numeric($field['magento_field'])){
|
| 110 |
+
$productData['shipping']=$field['magento_field'];
|
| 111 |
+
}else{
|
| 112 |
+
if(isset($this->productOrigData[$field['magento_field']])){
|
| 113 |
+
$productData['shipping']=$this->productOrigData[$field['magento_field']];
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
}elseif($field['wsp_field']=='minprice'){
|
| 119 |
+
if(is_numeric($field['magento_field'])){
|
| 120 |
+
|
| 121 |
+
$productData[$field['wsp_field']]=$this->_calculateMinPrice($field);
|
| 122 |
+
|
| 123 |
+
}else{
|
| 124 |
+
if(isset($this->productOrigData[$field['magento_field']])){
|
| 125 |
+
$productData[$field['wsp_field']]=$this->productOrigData[$field['magento_field']];
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
}
|
| 129 |
}else{
|
| 130 |
+
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')
|
| 131 |
+
->setCodeFilter($field['magento_field'])
|
| 132 |
+
->getFirstItem();
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
if($attributeInfo->getfrontend_input()=='select'){
|
| 136 |
+
$attrLabel=$productModel->getAttributeText($field['magento_field']);
|
| 137 |
+
$productData[$field['wsp_field']]=$attrLabel;
|
| 138 |
+
}else{
|
| 139 |
+
if(!isset($this->productOrigData[$field['magento_field']])){continue;}
|
| 140 |
+
$productData[$field['wsp_field']]=$this->productOrigData[$field['magento_field']];
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
|
|
|
|
| 144 |
}
|
| 145 |
+
|
| 146 |
|
| 147 |
}
|
| 148 |
+
|
| 149 |
+
$productData['producturl']=Mage::helper('catalog/product')->getProductUrl($productCollData['entity_id']);
|
| 150 |
+
|
| 151 |
$productsOutput[]=$productData;
|
| 152 |
}
|
| 153 |
+
|
|
|
|
| 154 |
$returnArr=array(
|
| 155 |
'status'=>'success',
|
| 156 |
'error_code'=>'0',
|
| 157 |
'data'=>$productsOutput
|
| 158 |
);
|
| 159 |
+
Mage::log('sending '.count($productsOutput).' products',null,'wplog.log');
|
| 160 |
+
echo json_encode($returnArr);
|
| 161 |
+
die;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
private function _calculateMinPrice($field){
|
| 165 |
+
|
| 166 |
+
if(!isset($field['extra'])){
|
| 167 |
+
$field['extra']='-1:a';
|
| 168 |
+
}
|
| 169 |
+
$ruleArr= explode(':',$field['extra']);
|
| 170 |
+
|
| 171 |
if($ruleArr[1]=='a'){
|
| 172 |
$costField=$this->_getMagentoFieldByWsField('cost');
|
| 173 |
if($costField){
|
| 174 |
$cost=$this->productOrigData[$costField];
|
| 175 |
if($ruleArr[0]=='-1'){
|
| 176 |
+
$minPrice=($cost*$field['magento_field'])/100+$cost;
|
| 177 |
}else{
|
| 178 |
+
$minPrice=$cost+$field['magento_field'];
|
| 179 |
}
|
| 180 |
+
}
|
| 181 |
+
}else{
|
| 182 |
+
$priceField=$this->_getMagentoFieldByWsField('price');
|
| 183 |
+
$price=$this->productOrigData[$priceField];
|
| 184 |
+
if($ruleArr[0]=='-1'){
|
| 185 |
+
$minPrice=$price-($price*$field['magento_field'])/100;
|
| 186 |
+
}else{
|
| 187 |
+
$minPrice=$price-$field['magento_field'];
|
| 188 |
+
}
|
| 189 |
+
}
|
| 190 |
+
return $minPrice;
|
| 191 |
+
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
private function _getMagentoFieldByWsField($wsfield){
|
| 195 |
+
|
| 196 |
$model = Mage::getModel('wisepricer_syncer/mapping');
|
| 197 |
$mappingId=$model->loadIdByWsfield($wsfield);
|
| 198 |
if($mappingId){
|
| 199 |
$mapping=$model->load($mappingId);
|
| 200 |
return $mapping->getmagento_field();
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
return false;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
private function _randString( $length ) {
|
| 207 |
+
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
| 208 |
+
$str='';
|
| 209 |
+
$size = strlen( $chars );
|
| 210 |
+
for( $i = 0; $i < $length; $i++ ) {
|
| 211 |
+
$str .= $chars[ rand( 0, $size - 1 ) ];
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
return $str;
|
| 215 |
+
}
|
| 216 |
|
| 217 |
public function loginAction(){
|
| 218 |
|
| 260 |
Mage::log(print_r('=========================================================',true),null,'wplog.log');
|
| 261 |
echo json_encode($returnArr);
|
| 262 |
}
|
| 263 |
+
|
| 264 |
+
public function logoutAction(){
|
| 265 |
+
|
| 266 |
$post = $this->getRequest()->getParams();
|
| 267 |
+
|
| 268 |
$magentoSessionId=Mage::getModel('core/cookie')->get('wpsession');
|
| 269 |
+
|
| 270 |
if($magentoSessionId!=$post['sesssionid']){
|
| 271 |
+
|
| 272 |
+
$returnArr=array(
|
| 273 |
+
'status'=>'failure',
|
| 274 |
+
'error_code'=>'771',
|
| 275 |
+
'error_details'=>'Unauthorized access.'
|
| 276 |
+
);
|
| 277 |
+
echo json_encode($returnArr);
|
| 278 |
+
die;
|
| 279 |
}
|
| 280 |
+
|
| 281 |
+
Mage::getModel('core/cookie')->delete('wpsession');
|
| 282 |
$returnArr=array(
|
| 283 |
'status'=>'success',
|
| 284 |
'error_code'=>'0'
|
| 285 |
);
|
| 286 |
|
| 287 |
echo json_encode($returnArr);
|
| 288 |
+
}
|
| 289 |
+
public function getpublicAction(){
|
| 290 |
+
|
| 291 |
+
$publickey=$this->_getpublickey();
|
| 292 |
+
|
| 293 |
$returnArr=array(
|
| 294 |
'status'=>'success',
|
| 295 |
'error_code'=>'0',
|
| 297 |
);
|
| 298 |
|
| 299 |
echo json_encode($returnArr);
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
protected function _getprivatekey(){
|
| 303 |
+
|
| 304 |
+
$licenseData =Mage::getModel('wisepricer_syncer/config')->load(1);
|
| 305 |
if(!$licenseData->getData()||$licenseData->getIs_confirmed()==0){
|
| 306 |
+
|
| 307 |
+
$returnArr=array(
|
| 308 |
+
'status'=>'failure',
|
| 309 |
+
'error_code'=>'769',
|
| 310 |
+
'error_details'=>'The user has not completed the integration.'
|
| 311 |
+
);
|
| 312 |
+
echo json_encode($returnArr);
|
| 313 |
+
die;
|
| 314 |
}
|
| 315 |
+
|
| 316 |
return $licenseData->getprivatekey();
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
protected function _getpublickey(){
|
| 320 |
+
|
| 321 |
+
$licenseData =Mage::getModel('wisepricer_syncer/config')->load(1);
|
| 322 |
if(!$licenseData->getData()||$licenseData->getIs_confirmed()==0){
|
| 323 |
+
|
| 324 |
+
$returnArr=array(
|
| 325 |
+
'status'=>'failure',
|
| 326 |
+
'error_code'=>'769',
|
| 327 |
+
'error_details'=>'The user has not completed the integration.'
|
| 328 |
+
);
|
| 329 |
+
echo json_encode($returnArr);
|
| 330 |
+
die;
|
| 331 |
}
|
| 332 |
+
|
| 333 |
return $licenseData->getpublickey();
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
protected function _decryptstring($str){
|
| 337 |
+
|
| 338 |
+
set_include_path(get_include_path().PS .BP.DS . 'lib'.DS.'phpseclib' . PS.BP.DS.'app'.DS.'code'.DS.'local'.DS.'Wisepricer'.DS.'Syncer'.DS.'lib'.DS.'phpseclib' );
|
| 339 |
+
include('Crypt'.DS.'RSA.php');
|
| 340 |
+
|
| 341 |
+
$rsa = new Crypt_RSA();
|
| 342 |
+
$rsa->loadKey($this->_getprivatekey());
|
| 343 |
+
return $rsa->decrypt($str);
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
public function repriceAction(){
|
| 347 |
Mage::log(print_r('Entered reprice action',true),null,'wplog.log');
|
| 348 |
set_time_limit (1800);
|
| 349 |
$licenseData =Mage::getModel('wisepricer_syncer/config')->load(1);
|
| 350 |
if(!$licenseData->getData()||$licenseData->getIs_confirmed()==0){
|
| 351 |
+
|
| 352 |
+
$returnArr=array(
|
| 353 |
+
'status'=>'failure',
|
| 354 |
+
'error_code'=>'769',
|
| 355 |
+
'error_details'=>'The user has not completed the integration.'
|
| 356 |
+
);
|
| 357 |
+
echo json_encode($returnArr);
|
| 358 |
+
die;
|
| 359 |
}
|
| 360 |
+
|
| 361 |
$post = $this->getRequest()->getParams();
|
| 362 |
+
|
| 363 |
$magentoSessionId=Mage::getModel('core/cookie')->get('wpsession');
|
| 364 |
Mage::log(print_r('Received session'.$post['sesssionid'],true),null,'wplog.log');
|
| 365 |
+
Mage::log(print_r('Stored session'.$magentoSessionId,true),null,'wplog.log');
|
| 366 |
if($magentoSessionId!=$post['sesssionid']){
|
| 367 |
+
|
| 368 |
+
$returnArr=array(
|
| 369 |
+
'status'=>'failure',
|
| 370 |
+
'error_code'=>'771',
|
| 371 |
+
'error_details'=>'Unauthorized access.'
|
| 372 |
+
);
|
| 373 |
+
echo json_encode($returnArr);
|
| 374 |
+
die;
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
$productsEncoded= $post['products'];
|
| 378 |
$products =json_decode(urldecode ($productsEncoded));
|
| 379 |
$responseArr=array();
|
| 380 |
$sucessCounter=0;
|
| 381 |
$failedCounter=0;
|
| 382 |
+
Mage::log(print_r('repricing '.count($products),true),null,'wplog.log');
|
| 383 |
+
$repriceModel=Mage::getModel('wisepricer_syncer/reprice');
|
| 384 |
+
|
| 385 |
foreach ($products as $prodArr) {
|
| 386 |
+
|
| 387 |
if ($repriceModel->checkIfSkuExists($prodArr->sku)) {
|
| 388 |
+
try {
|
| 389 |
+
|
| 390 |
+
$repriceModel->updatePrices($prodArr);
|
| 391 |
+
$responseArr[]=array('sku'=>$prodArr->sku,'price'=>$prodArr->price,'error_code'=>'0');
|
| 392 |
+
$sucessCounter++;
|
| 393 |
+
|
| 394 |
+
} catch (Exception $exc) {
|
| 395 |
+
$responseArr[]=array('sku'=>$prodArr->sku,'error_code'=>'444','error_details'=>$exc->getMessage());
|
| 396 |
+
$failedCounter++;
|
| 397 |
+
}
|
| 398 |
}else{
|
| 399 |
+
$responseArr[]=array('sku'=>$prodArr->sku,'error_code'=>'333','error_details'=>'SKU could not be loaded');
|
| 400 |
+
$failedCounter++;
|
| 401 |
+
|
| 402 |
}
|
| 403 |
+
|
| 404 |
+
|
| 405 |
}
|
| 406 |
+
Mage::log(print_r('finished repricing',true),null,'wplog.log');
|
| 407 |
+
if($sucessCounter==0){
|
| 408 |
$error_code=-1;
|
| 409 |
$error_details='Magento could not update any product.';
|
| 410 |
+
}else{
|
| 411 |
$error_code=0;
|
| 412 |
$error_details='';
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
$returnArr=array();
|
| 416 |
+
$returnArr['ResultData']= $responseArr;
|
| 417 |
+
$returnArr['Succeeded']=$sucessCounter;
|
| 418 |
+
$returnArr['Failed']=$failedCounter;
|
| 419 |
+
$returnArr['error_code']=$error_code;
|
| 420 |
+
$returnArr['error_details']=$error_details;
|
| 421 |
+
echo json_encode($returnArr);
|
| 422 |
+
die;
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
public function reindexAction(){
|
| 426 |
+
|
| 427 |
Mage::log(print_r('Entered reindex action',true),null,'wplog.log');
|
| 428 |
|
| 429 |
$licenseData =Mage::getModel('wisepricer_syncer/config')->load(1);
|
| 430 |
if(!$licenseData->getData()||$licenseData->getIs_confirmed()==0){
|
| 431 |
+
|
| 432 |
+
$returnArr=array(
|
| 433 |
+
'status'=>'failure',
|
| 434 |
+
'error_code'=>'769',
|
| 435 |
+
'error_details'=>'The user has not completed the integration.'
|
| 436 |
+
);
|
| 437 |
+
echo json_encode($returnArr);
|
| 438 |
+
die;
|
| 439 |
}
|
| 440 |
+
|
| 441 |
$post = $this->getRequest()->getParams();
|
| 442 |
+
|
| 443 |
$magentoSessionId=Mage::getModel('core/cookie')->get('wpsession');
|
| 444 |
//Mage::log(print_r('Received session'.$post['sesssionid'],true),null,'wplog.log');
|
| 445 |
//Mage::log(print_r('Stored session'.$magentoSessionId,true),null,'wplog.log');
|
| 446 |
if($magentoSessionId!=$post['sesssionid']){
|
| 447 |
+
|
| 448 |
+
$returnArr=array(
|
| 449 |
+
'status'=>'failure',
|
| 450 |
+
'error_code'=>'771',
|
| 451 |
+
'error_details'=>'Unauthorized access.'
|
| 452 |
+
);
|
| 453 |
+
echo json_encode($returnArr);
|
| 454 |
+
die;
|
| 455 |
+
}
|
| 456 |
Mage::getSingleton('index/indexer')->getProcessByCode('catalog_product_price')->reindexAll();
|
| 457 |
+
}
|
| 458 |
+
|
| 459 |
+
public function generatejasonAction(){
|
| 460 |
+
$result['products']=array(
|
| 461 |
+
array(
|
| 462 |
+
'sku'=>'zol_r_sm',
|
| 463 |
+
'price'=>'303.3'
|
| 464 |
+
),
|
| 465 |
+
array(
|
| 466 |
+
'sku'=>'4fasd5f5',
|
| 467 |
+
'price'=>'770.0'
|
| 468 |
+
)
|
| 469 |
+
);
|
| 470 |
+
echo json_encode($result['products']);
|
| 471 |
+
die;
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
public function pingAction(){
|
| 475 |
+
|
| 476 |
+
$result['storeurl']=Mage::getUrl();
|
| 477 |
+
echo json_encode($result);
|
| 478 |
+
die;
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
public function versAction(){
|
| 482 |
+
$mage=Mage::getVersion();
|
| 483 |
+
$ext=(string) Mage::getConfig()->getNode()->modules->Wisepricer_Syncer->version;
|
| 484 |
+
$result=array('mage'=>$mage,'ext'=>$ext);
|
| 485 |
+
echo json_encode($result);die;
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
}
|
| 489 |
?>
|
app/code/local/Wisepricer/Syncer/etc/config.xml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
<config>
|
| 3 |
<modules>
|
| 4 |
<Wisepricer_Syncer>
|
| 5 |
-
<version>1.1.2.
|
| 6 |
<url>http://www.wisepricer.com/index.php</url>
|
| 7 |
<modulename>Wisepricer Syncer</modulename>
|
| 8 |
</Wisepricer_Syncer>
|
| 2 |
<config>
|
| 3 |
<modules>
|
| 4 |
<Wisepricer_Syncer>
|
| 5 |
+
<version>1.1.2.9</version>
|
| 6 |
<url>http://www.wisepricer.com/index.php</url>
|
| 7 |
<modulename>Wisepricer Syncer</modulename>
|
| 8 |
</Wisepricer_Syncer>
|
app/code/local/Wisepricer/Syncer/sql/syncer_setup/{mysql4-install-1.1.2.8.php → mysql4-install-1.1.2.9.php}
RENAMED
|
File without changes
|
package.xml
CHANGED
|
@@ -1,18 +1,18 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>Wisepricer_Syncer</name>
|
| 4 |
-
<version>1.1.2.
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
<summary>WisePricer- Beat your competition</summary>
|
| 10 |
<description>WisePricer is a new tool that allows you to Track & monitor successful online retailers and update your store prices in real-time. With WisePricer you’ll never get left behind the competition.</description>
|
| 11 |
-
<notes>
|
| 12 |
-
<authors><author><name>Moshe</name><user>
|
| 13 |
-
<date>2012-10-
|
| 14 |
-
<time>
|
| 15 |
-
<contents><target name="
|
| 16 |
<compatible/>
|
| 17 |
-
<dependencies
|
| 18 |
</package>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>Wisepricer_Syncer</name>
|
| 4 |
+
<version>1.1.2.9</version>
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
<summary>WisePricer- Beat your competition</summary>
|
| 10 |
<description>WisePricer is a new tool that allows you to Track & monitor successful online retailers and update your store prices in real-time. With WisePricer you’ll never get left behind the competition.</description>
|
| 11 |
+
<notes>faster import</notes>
|
| 12 |
+
<authors><author><name>Moshe</name><user>moshewp</user><email>moshe@wisepricer.com</email></author></authors>
|
| 13 |
+
<date>2012-10-30</date>
|
| 14 |
+
<time>09:25:54</time>
|
| 15 |
+
<contents><target name="magelocal"><dir name="Wisepricer"><dir name="Syncer"><dir name="Block"><dir name="Adminhtml"><file name="Mapping.php" hash="ce3249eb8500db5ba9a60eb788437fed"/><file name="Register.php" hash="ed2ffde3237ecba2dbdd6002b5077af3"/></dir></dir><dir name="Helper"><file name="Data.php" hash="025b73c04ab0ca01d2e7c75aaad7fea6"/></dir><dir name="Model"><dir name="Adminhtml"><file name="Attributes.php" hash="2d50a30f0e7df8cf5791aea101f9008a"/></dir><file name="Config.php" hash="d669c3dc977ddf71a58c90fa8df3180c"/><file name="Mapping.php" hash="d924ae8bcf54a3ca1224e8680d847fee"/><dir name="Mysql4"><dir name="Config"><file name="Collection.php" hash="c7c7b6844e3ff8893163c392f4132f30"/></dir><file name="Config.php" hash="61b7eb73489844aa0ee041c216bab2db"/><dir name="Mapping"><file name="Collection.php" hash="c0f15143db582e070cfb83de92c57d09"/></dir><file name="Mapping.php" hash="d97574adda931ce798964c67041f6af5"/></dir><file name="Reprice.php" hash="dd1f6f4b0031940b1c695aefbf8f47e9"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="SyncerController.php" hash="453e3352d35836128a24280471362866"/></dir><file name="ProductsController.php" hash="7c899d388b55ddc29b74d649d06f9720"/></dir><dir name="etc"><file name="config.xml" hash="d02795250e7b492701e299e36b5c75e5"/></dir><dir name="lib"><dir name="phpseclib"><dir name="Crypt"><file name="AES.php" hash="dd67dd1dbc7706e6c740e8430054d5e0"/><file name="DES.php" hash="47ac443f1edd2833cdc2f4eb80aa9a71"/><file name="Hash.php" hash="9be22f6426f2176caebb34a6cd2cb579"/><file name="RC4.php" hash="c6ec724c3a5d807d5ea4645518c37d29"/><file name="RSA.php" hash="9bd5734f28d149d183c603643f6dbbb4"/><file name="Random.php" hash="5befc55c3423792c0cd50bc6d4f527b1"/><file name="Rijndael.php" hash="7a92c95c750dd9ec1b8ce92915b4aa35"/><file name="TripleDES.php" hash="07c384b505d52802803313126e9e3836"/></dir><dir name="Math"><file name="BigInteger.php" hash="61aa9373ea606c928187d168159ac3f8"/></dir><dir name="Net"><file name="SFTP.php" hash="029f797c16ddd23b1d65636a72141115"/><file name="SSH1.php" hash="818d83815fe9bb5741594226bbdad975"/><file name="SSH2.php" hash="db5145effae044c7a1f6e7d778b566f5"/></dir><dir name="PHP"><dir name="Compat"><dir name="Function"><file name="array_fill.php" hash="840a674cac272c5588fa59f9421ed9a3"/><file name="bcpowmod.php" hash="4cb8fab0ee419f4b5a626980bbf04938"/><file name="str_split.php" hash="85cb5961afa62dde933190ee851a6d9a"/></dir></dir></dir></dir></dir><dir name="sql"><dir name="syncer_setup"><file name="mysql4-install-1.1.2.9.php" hash="25b666bcc330f7aeebc2c9759f82273f"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Wisepricer_Syncer.xml" hash="838dc229469d27db4c96a49591b12f55"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="syncer.xml" hash="a9d0f0b5af6b7bc28fb3c3b897c1773c"/></dir><dir name="template"><dir name="wisepricer"><file name="mapping.phtml" hash="8c8f177dc6f5097c422c6bc783542b5f"/></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="images"><dir name="wisepricer"><file name="bullet-green.png" hash="78d917a9d9aea11366bada6e0ae53931"/><file name="validation_advice_bg.gif" hash="ffdad80de989e3b04a977be3778c4347"/><file name="wp-alert-icon.png" hash="0dbbadfbbe2329098d03f8351aa2eaf2"/><file name="wp-logo.png" hash="48db98cdfc570336c942271352f31094"/><file name="wp-save-btn.png" hash="6d8e02c7f5e54dcc705e6436f126c66d"/></dir></dir><dir name="wisepricer"><file name="chosen-sprite.png" hash="8e70d120437ffc6a1bf7cebeca292d5c"/><file name="chosen.css" hash="a1b7280ed62dbe210257027dd6bfa073"/><file name="chosen.proto.js" hash="b98b346e60d90e7e3f83106cf860dacd"/><file name="myprototype.js" hash="3b4b13dad33b475e11feb26fd3468ecc"/><file name="prototype17.js" hash="3b4b13dad33b475e11feb26fd3468ecc"/><file name="wisepricer.css" hash="bab3eada0e2a974b1f8f7a87cbf5bb9c"/></dir></dir></dir></dir></target></contents>
|
| 16 |
<compatible/>
|
| 17 |
+
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
| 18 |
</package>
|
