Example #1
0
 /**
  * Stripped down version of AddItemToCart for use with the SOAP uploader
  */
 public function AddSoapProduct($intDocumentId, $objProduct, $intQty = 1, $strDescription = false, $fltSell = false, $fltDiscount = 0, $mixCartType = false, $intGiftItemId = 0)
 {
     if (!$mixCartType) {
         $mixCartType = CartType::cart;
     }
     $objItem = new SroItem();
     $objItem->qty = abs($intQty);
     if ($objProduct->id) {
         $objItem->product_id = $objProduct->id;
     }
     $objItem->cart_type = $mixCartType;
     $objItem->description = $strDescription;
     $objItem->sell = $fltSell;
     $objItem->sell_discount = $fltSell;
     //Discount comes in as 0 from LS, but we use this field for override price
     $objItem->sell_base = $fltSell;
     $objItem->sell_total = $objItem->sell_base * $objItem->qty;
     $objItem->code = $objProduct->OriginalCode;
     $objItem->discount = "";
     $objItem->sro_id = $intDocumentId;
     if (!$objItem->save()) {
         Yii::log("Failed to save soap document item " . print_r($objItem->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
     }
     return $objItem->id;
 }
 /**
  * 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;
 }