Example #1
0
 public function customValidation($attribute, $params)
 {
     if ($this->emailPhone != '' && $this->orderId != '') {
         $intCustomer = null;
         $objCustomer = null;
         $objCart = null;
         $found = 0;
         //Is this a customer email address, or possible an email attached to an SRO
         if (strtolower(substr($this->orderId, 0, 2)) == "s-") {
             $objSro = Sro::model()->findByAttributes(array('customer_email_phone' => $this->emailPhone, 'ls_id' => $this->orderId));
             if (!$objSro instanceof SRO) {
                 $this->addError($this->orderId, Yii::t('yii', 'Order/Email combination not found'));
                 Yii::app()->clientScript->registerScript('orderalert', 'alert("Order/Email combination not found");');
             } else {
                 $this->orderType = CartType::sro;
             }
         } else {
             //Regular Order
             $objCustomer = Customer::LoadByEmail($this->emailPhone);
             if (!$objCustomer instanceof Customer) {
                 $this->addError($this->emailPhone, Yii::t('yii', 'Email address not found'));
                 Yii::app()->clientScript->registerScript('emailalert', 'alert("Email address not found");');
             } else {
                 $objCart = Cart::model()->findByAttributes(array('id_str' => $this->orderId, 'customer_id' => $objCustomer->id));
                 if (!$objCart instanceof Cart) {
                     $this->addError($this->orderId, Yii::t('yii', 'Order/Email combination not found'));
                     Yii::app()->clientScript->registerScript('orderalert', 'alert("Order/Email combination not found");');
                 } else {
                     $this->orderType = CartType::order;
                 }
             }
         }
     }
 }
 /**
  * Show an SRO. Does not require the customer to be logged in to view
  */
 public function actionView()
 {
     $this->layout = '//layouts/column2';
     $strLink = Yii::app()->getRequest()->getQuery('code');
     if (empty($strLink)) {
         Yii::app()->controller->redirect(Yii::app()->createUrl('site/index'));
     }
     //Use our class variable which is accessible from the view
     $model = Sro::model()->findByAttributes(array('linkid' => $strLink));
     if (!$model instanceof Sro) {
         _xls_404();
     }
     $this->render('sro', array('model' => $model));
 }
 public function run()
 {
     $model = new LookupForm();
     if (isset($_POST['LookupForm'])) {
         $model->attributes = $_POST['LookupForm'];
         if ($model->validate()) {
             //Because our validate already checks to see if it's a valid combination, we can trust loading here and just redir
             if ($model->orderType == CartType::order) {
                 $objCustomer = Customer::LoadByEmail($model->emailPhone);
                 $objCart = Cart::model()->findByAttributes(array('id_str' => $model->orderId, 'customer_id' => $objCustomer->id));
                 Yii::app()->controller->redirect($objCart->Link);
             }
             if ($model->orderType == CartType::sro) {
                 $objSro = Sro::model()->findByAttributes(array('customer_email_phone' => $model->emailPhone, 'ls_id' => $model->orderId));
                 Yii::app()->controller->redirect($objSro->Link);
             }
         }
     }
     $this->render('index', array('model' => $model));
 }
 /**
  * Document Flush
  *
  * @param string $passkey
  * @return string
  */
 public function document_flush($passkey)
 {
     if (!$this->check_passkey($passkey)) {
         return self::FAIL_AUTH;
     }
     if (_xls_get_conf('DEBUG_RESET', 0) == 1) {
         Yii::log('Skipped document flush operation due to DEBUG mode', CLogger::LEVEL_WARNING, 'application.' . __CLASS__ . "." . __FUNCTION__);
         return self::OK;
     }
     try {
         SroRepair::model()->deleteAll();
         SroItem::model()->deleteAll();
         Sro::model()->deleteAll();
         Cart::model()->updateAll(array('document_id' => null));
         //We need to make Document items for anything not Invoiced manual to roll back
         $objCarts = Document::model()->findAll("order_type = :type AND (status=:status1 OR status=:status2 OR status=:status3)", array(':type' => CartType::order, ':status1' => OrderStatus::Requested, ':status2' => OrderStatus::Processed, ':status3' => OrderStatus::PartiallyReceived));
         foreach ($objCarts as $objCart) {
             foreach ($objCart->documentItems as $item) {
                 $item->qty = 0;
                 $item->save();
                 $item->product->SetAvailableInventory();
                 $item->delete();
             }
             $objCart->delete();
         }
         //Then delete everytihing else
         DocumentItem::model()->deleteAll();
         Document::model()->deleteAll();
         Yii::app()->db->createCommand("alter table " . Document::model()->tableName() . " auto_increment=1;")->execute();
         Yii::app()->db->createCommand("alter table " . DocumentItem::model()->tableName() . " auto_increment=1;")->execute();
         Yii::app()->db->createCommand("alter table " . Sro::model()->tableName() . " auto_increment=1;")->execute();
         Yii::app()->db->createCommand("alter table " . SroItem::model()->tableName() . " auto_increment=1;")->execute();
         Yii::app()->db->createCommand("alter table " . SroRepair::model()->tableName() . " auto_increment=1;")->execute();
         //We shouldn't have anything in the cart table that's not an original order, so remove the following if they exist
         //ToDo: this shouldn't be in production because we will have removed Quote lines from _cart during install
         $objCarts = Cart::model()->findAllByAttributes(array('cart_type' => CartType::quote));
         foreach ($objCarts as $objCart) {
             foreach ($objCart->cartItems as $item) {
                 $item->delete();
             }
             $objCart->delete();
         }
         //ToDo: this shouldn't be in production because we will have removed SRO lines from _cart during install
         $objCarts = Cart::model()->findAllByAttributes(array('cart_type' => CartType::sro));
         foreach ($objCarts as $objCart) {
             foreach ($objCart->cartItems as $item) {
                 $item->delete();
             }
             $objCart->delete();
         }
         //ToDo: this shouldn't be in production because we will have removed O- from _cart during install
         //Delete anything here that's just a pure Order from LS from our Cart Table
         $objCarts = Cart::model()->findAll("cart_type = :type and id_str LIKE 'O-%'", array(':type' => CartType::order));
         foreach ($objCarts as $objCart) {
             foreach ($objCart->cartItems as $item) {
                 $item->delete();
             }
             $objCart->delete();
         }
         //Delete any Web Orders that have been reuploaded from Lightspeed already
         $objCarts = Cart::model()->findAll("cart_type = :type AND status<>:status1 AND status<>:status2 AND status<>:status3", array(':type' => CartType::order, ':status1' => OrderStatus::AwaitingPayment, ':status2' => OrderStatus::AwaitingProcessing, ':status3' => OrderStatus::Downloaded));
         foreach ($objCarts as $objCart) {
             foreach ($objCart->cartItems as $item) {
                 $item->delete();
             }
             $objCart->delete();
         }
         //Delete any carts older than our timeout that don't have a customer ID attached (since those can always be restored)
         Cart::GarbageCollect();
     } catch (Exception $e) {
         Yii::log('SOAP ERROR : In flushing document tables ' . $e, 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
         return self::UNKNOWN_ERROR;
     }
     return self::OK;
 }
Example #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSro()
 {
     return $this->hasOne(Sro::className(), ['id' => 'sro_id']);
 }