예제 #1
0
 public static function CreateEvent($strModule, $strController, $strAction, $data_id = null, $product_id = null)
 {
     if ($strController == "amazon") {
         $MerchantID = _xls_get_conf('AMAZON_MERCHANT_ID');
         $MarketplaceID = _xls_get_conf('AMAZON_MARKETPLACE_ID');
         $MWS_ACCESS_KEY_ID = _xls_get_conf('AMAZON_MWS_ACCESS_KEY_ID');
         $MWS_SECRET_ACCESS_KEY = _xls_get_conf('AMAZON_MWS_SECRET_ACCESS_KEY');
         if (empty($MerchantID) || empty($MarketplaceID) || empty($MWS_ACCESS_KEY_ID) || empty($MWS_SECRET_ACCESS_KEY)) {
             return false;
         }
     }
     //Check to make sure it's not duplicate
     $objTask = TaskQueue::model()->findByAttributes(array('module' => $strModule, 'controller' => $strController, 'action' => $strAction, 'data_id' => $data_id, 'product_id' => $product_id));
     if ($objTask instanceof TaskQueue) {
         return;
     }
     $objTask = new TaskQueue();
     $objTask->module = $strModule;
     $objTask->controller = $strController;
     $objTask->action = $strAction;
     $objTask->data_id = $data_id;
     $objTask->product_id = $product_id;
     if (!$objTask->save()) {
         Yii::log("Error creating Task {$strModule}, {$strController}, {$strAction} " . print_r($objTask->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
     }
 }
예제 #2
0
 /**
  * See if we have any events to fire
  */
 public function actionIndex()
 {
     $criteria = new CDbCriteria();
     $criteria->compare('active', 1);
     $criteria->compare('category', 'CEvent', true, 'AND');
     $objModules = Modules::model()->findAll($criteria);
     foreach ($objModules as $objModule) {
         //Find and our tasks (one of each type this cron cycle)
         $criteria = new CDbCriteria();
         $criteria->select = 'action';
         $criteria->distinct = true;
         $criteria->compare('controller', $objModule->module);
         $objTaskTypes = TaskQueue::model()->findAll($criteria);
         Yii::import('ext.' . $objModule->module . "." . $objModule->module);
         $component = new $objModule->module();
         $component->init();
         //Run init on module first
         foreach ($objTaskTypes as $objType) {
             //Locate a task of this type
             $objTask = TaskQueue::model()->findByAttributes(array('module' => 'integration', 'controller' => $objModule->module, 'action' => $objType->action));
             Yii::log("Found TaskQueue item " . $objTask->controller . " " . $objTask->action, 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
             $actionName = "OnAction" . ucfirst($objTask->action);
             $objEvent = new CEventTaskQueue(get_class($this), $objTask->data_id, $objTask->product_id);
             Yii::log("Cron action " . $actionName . " on object " . print_r($objEvent, true), 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
             //Run the action and get a true/false if it was successful
             $retVal = $component->{$actionName}($objEvent);
             if ($retVal) {
                 Yii::log("Successfully processed by Amazon, so deleting task", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                 $objTask->delete();
                 //Successfully ran, so delete entry
             } else {
                 Yii::log("Still waiting on Amazon, will check again next time", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                 $objTask->modified = new CDbExpression('NOW()');
                 $objTask->save();
             }
         }
     }
     //Create a Download Orders event to force any other subsystems to check for new orders
     if (date("i") % 10 == 0) {
         $objEvent = new CEventOrder('CronController', 'onDownloadOrders');
         _xls_raise_events('CEventOrder', $objEvent);
     }
 }
 /**
  * Product lookup and optional delete, shows inventory numbers
  */
 public function actionProducts()
 {
     if (isset($_POST['pk']) && isset($_POST['name']) && isset($_POST['value'])) {
         if ($_POST['name'] == 'code' && $_POST['value'] == "") {
             $items = CartItem::model()->findAll("product_id=" . $_POST['pk'] . " AND (cart_type=" . CartType::order . " OR cart_type=" . CartType::awaitpayment . ")");
             if ($items) {
                 echo "You cannot delete a product that has been used on an order";
             } else {
                 _dbx("set foreign_key_checks=0;");
                 Product::model()->updateAll(array('image_id' => null), 'id =' . $_POST['pk']);
                 Images::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 ProductCategoryAssn::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 ProductRelated::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 ProductRelated::model()->deleteAllByAttributes(array('related_id' => $_POST['pk']));
                 ProductTags::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 ProductQtyPricing::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 ProductText::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 WishlistItem::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 TaskQueue::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 Product::model()->deleteByPk($_POST['pk']);
                 _dbx("set foreign_key_checks=1;");
                 echo "delete";
             }
         } else {
             echo Yii::t('admin', 'You cannot change a product code here. Delete the code to remove it manually from the Web Store database');
         }
     } else {
         $model = new Product();
         if (isset($_GET['q'])) {
             $model->code = $_GET['q'];
         }
         $this->render("products", array('model' => $model));
     }
 }