Exemplo n.º 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 DocumentItem();
     $objItem->qty = abs($intQty);
     if ($objProduct->id) {
         $objItem->product_id = $objProduct->id;
     }
     if (empty($strDescription)) {
         $strDescription = $objProduct->title;
     }
     $objItem->cart_type = $mixCartType;
     $objItem->description = $strDescription;
     $objItem->gift_registry_item = $intGiftItemId;
     $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->datetime_added = new CDbExpression('NOW()');
     $objItem->document_id = $intDocumentId;
     if (!$objItem->save()) {
         Yii::log("Failed to save soap document item " . print_r($objItem->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
     }
     $this->UpdateDocument();
     return $objItem->id;
 }
Exemplo n.º 2
0
 /**
  * Calculates pending order qty to count against available
  * inventory by searching for Requested or Awaiting Processing orders
  * Because we have our cart table and our documents table, we have to get both numbers
  */
 public function CalculateReservedInventory()
 {
     //Pending orders not yet converted to Invoice
     $intReservedA = $this->getDbConnection()->createCommand("SELECT SUM(qty) FROM " . CartItem::model()->tableName() . " AS a\n\t\t\t\t\tLEFT JOIN " . Cart::model()->tableName() . " AS b ON a.cart_id=b.id\n\t\t\t\t\tLEFT JOIN " . Document::model()->tableName() . " AS c ON b.document_id=c.id\n\t\t\t\t\tWHERE\n\t\t\t\t\ta.product_id=" . $this->id . " AND b.cart_type=" . CartType::order . "\n\t\t\t\t\tAND (b.status='" . OrderStatus::Requested . "' OR b.status='" . OrderStatus::AwaitingProcessing . "'\n\t\t\t\t\t\tOR b.status='" . OrderStatus::Downloaded . "')\n\t\t\t\t\tAND (c.status IS NULL OR c.status='" . OrderStatus::Requested . "');")->queryScalar();
     if (empty($intReservedA)) {
         $intReservedA = 0;
     }
     //Unattached orders (made independently in Lightspeed)
     $intReservedB = $this->getDbConnection()->createCommand("SELECT SUM(qty) from " . DocumentItem::model()->tableName() . " AS a\n\t\t\t\t\tLEFT JOIN " . Document::model()->tableName() . " AS b ON a.document_id=b.id\n\t\t\t\t\tWHERE\n\t\t\t\t\ta.product_id=" . $this->id . " AND b.order_type=" . CartType::order . "\n\t\t\t\t\tAND cart_id IS NULL AND left(order_str,3)='WO-' AND (b.status='" . OrderStatus::Requested . "');")->queryScalar();
     if (empty($intReservedB)) {
         $intReservedB = 0;
     }
     return $intReservedA + $intReservedB;
 }
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * @brief rss
  **/
 function rss()
 {
     $oRss =& getView('rss');
     $oDocumentModel =& getModel('document');
     $oModuleModel =& getModel('module');
     $homepage_info = $oModuleModel->getModuleConfig('homepage');
     if ($homepage_info->use_rss != 'Y') {
         return new Object(-1, 'msg_rss_is_disabled');
     }
     $output = executeQueryArray('homepage.getRssList', $args);
     if ($output->data) {
         foreach ($output->data as $key => $val) {
             unset($obj);
             $obj = new DocumentItem(0);
             $obj->setAttribute($val);
             $document_list[] = $obj;
         }
     }
     $oRss->rss($document_list, $homepage_info->browser_title);
     $this->setTemplatePath($oRss->getTemplatePath());
     $this->setTemplateFile($oRss->getTemplateFile());
 }
Exemplo n.º 5
0
 /**
  * @brief rss
  **/
 function rss()
 {
     $oRss =& getView('rss');
     $oRssModel =& getModel('rss');
     $oDocumentModel =& getModel('document');
     if ($this->planet->isHome()) {
         if ($this->module_info->use_rss != 'Y') {
             return new Object(-1, 'msg_rss_is_disabled');
         }
     } else {
         $rss_config = $oRssModel->getRssModuleConfig($this->module_srl);
         if ($rss_config->open_rss != 'Y') {
             return new Object(-1, 'msg_rss_is_disabled');
         }
         $args->module_srl = $this->module_srl;
     }
     $output = executeQueryArray('planet.getRssList', $args);
     if ($output->data) {
         foreach ($output->data as $key => $val) {
             unset($obj);
             $obj = new DocumentItem(0);
             $obj->setAttribute($val);
             $document_list[] = $obj;
         }
     }
     $oRss->rss($document_list, $this->planet->getBrowserTitle());
     $this->setTemplatePath($oRss->getTemplatePath());
     $this->setTemplateFile($oRss->getTemplateFile());
 }
 function rss()
 {
     $oRss =& getView('rss');
     $oDocumentModel =& getModel('document');
     $oModuleModel =& getModel('module');
     $output = executeQueryArray('textylehub.getRssList', $args);
     if ($output->data) {
         foreach ($output->data as $key => $val) {
             unset($obj);
             $obj = new DocumentItem(0);
             $obj->setAttribute($val);
             $document_list[] = $obj;
         }
     }
     $oRss->rss($document_list, $this->module_info->browser_title);
     $this->setTemplatePath($oRss->getTemplatePath());
     $this->setTemplateFile($oRss->getTemplateFile());
 }