/** * Default action is product display. This action requires the product id to be passed. * If we do not receive this id, redirect back to the home page since something * went wrong. */ public function actionView() { $id = Yii::app()->getRequest()->getQuery('id'); if (empty($id)) { _xls_404(); } //Load a product and display the information $model = $this->objProduct = Product::model()->findByPk($id); if (!$model || !$model->IsDisplayable) { _xls_404(); } //If our request_url (based on description) has changed, redirect properly if ($model->request_url != Yii::app()->getRequest()->getQuery('name')) { _xls_301($model->Link); } //Set breadcrumbs $this->breadcrumbs = $model->Breadcrumbs; $this->pageImageUrl = $model->SmallImageAbsolute; $objWishlistAddForm = new WishlistAddForm(); $objWishlistAddForm->id = $this->objProduct->id; $objWishlistAddForm->qty = 1; $objWishlistAddForm->lists = $objWishlistAddForm->getLists(); $objWishlistAddForm->gift_code = Wishlist::LoadFirstCode(); $this->setPageTitle($model->PageTitle); $this->pageDescription = $model->PageDescription; $this->canonicalUrl = $model->canonicalUrl; $this->returnUrl = $model->absoluteLink; $model->intQty = 1; //Raise any events first $objEvent = new CEventProduct(get_class($this), 'onActionProductView', $model); _xls_raise_events('CEventProduct', $objEvent); $this->widget('ext.wscartanimate.wscartanimate'); $this->widget('ext.wsproduct.wsproduct'); $this->render('index', array('model' => $model, 'WishlistAddForm' => $objWishlistAddForm)); }
/** * 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); } }
/** * ORM level methods */ public function DeleteImage() { if ($this->image_path && file_exists(Images::GetImagePath($this->image_path))) { @unlink($this->GetPath()); } $objEvent = new CEventPhoto('Images', 'onDeletePhoto', null, null, null); if (isset($this->ImagesCloud) && isset($this->ImagesCloud[0])) { $objEvent->cloudinary_public_id = $this->ImagesCloud[0]->cloudinary_public_id; } $objEvent->s3_path = $this->image_path; _xls_raise_events('CEventPhoto', $objEvent); }
protected function triggerEmailCampaign($objCustomer, $strTrigger) { $objEvent = new CEventCustomer('MyAccountController', $strTrigger, $objCustomer); _xls_raise_events('CEventCustomer', $objEvent); }
/** * Flushes a DB Table * This gets called during a Reset Store Products for the following tables in sequence: * Product, Category, Tax, TaxCode, TaxStatus, Family, ProductRelated, ProductQtyPricing, Images * * @param string $passkey * @param string $strObj * @return string */ public function db_flush($passkey, $strObj) { if (!$this->check_passkey($passkey)) { return self::FAIL_AUTH; } if (_xls_get_conf('DEBUG_RESET', 0) == 1) { _xls_log("Skipped flush operation due to DEBUG mode"); return self::OK; } if (!class_exists($strObj)) { _xls_log("SOAP ERROR : There is no object type of {$strObj}"); return self::NOT_FOUND; } if (in_array($strObj, array('Cart', 'Configuration', 'ConfigurationType', 'CartType', 'ViewLogType'))) { _xls_log("SOAP ERROR : Objects of type {$strObj} are not allowed for flushing"); return self::UNKNOWN_ERROR; } /** Lightspeed will send commands to flush the following tables Product Category Tax TaxCode TaxStatus Family ProductRelated ProductQtyPricing Images */ Yii::app()->db->createCommand('SET FOREIGN_KEY_CHECKS=0;')->execute(); //For certain tables, we flush related data as well switch ($strObj) { case "Product": //Yii::app()->db->createCommand()->truncateTable('xlsws_product_image_assn'); Yii::app()->db->createCommand()->truncateTable('xlsws_product_category_assn'); Yii::app()->db->createCommand()->truncateTable('xlsws_classes'); Yii::app()->db->createCommand()->truncateTable('xlsws_family'); Yii::app()->db->createCommand()->truncateTable('xlsws_tags'); Yii::app()->db->createCommand()->truncateTable('xlsws_product_tags'); $strTableName = "xlsws_product"; break; case "Category": Yii::app()->db->createCommand()->truncateTable('xlsws_product_category_assn'); $strTableName = "xlsws_category_addl"; //We blank our caching table, not the real table break; case "Tax": $strTableName = "xlsws_tax"; break; case "TaxCode": $strTableName = "xlsws_tax_code"; break; case "TaxStatus": $strTableName = "xlsws_tax_status"; break; case "Family": $strTableName = "xlsws_family"; break; case "ProductRelated": $strTableName = "xlsws_product_related"; break; case "ProductQtyPricing": $strTableName = "xlsws_product_qty_pricing"; break; case "Images": //Because we could have a huge number of Image entries, we need to just use SQL/DAO directly $cmd = Yii::app()->db->createCommand("SELECT image_path FROM xlsws_images WHERE image_path IS NOT NULL AND left(image_path,2)<>'//'"); $dataReader = $cmd->query(); while (($image = $dataReader->read()) !== false) { @unlink(Images::GetImagePath($image['image_path'])); } $cmd = Yii::app()->db->createCommand("SELECT cloudinary_public_id FROM xlsws_images_cloud WHERE cloudinary_public_id IS NOT NULL"); $dataReader = $cmd->query(); while (($image = $dataReader->read()) !== false) { $objEvent = new CEventPhoto('Images', 'onDeletePhoto', null, null, null); $objEvent->cloudinary_public_id = $image['cloudinary_public_id']; _xls_raise_events('CEventPhoto', $objEvent); Yii::app()->db->createCommand("delete FROM xlsws_images_cloud WHERE cloudinary_public_id='" . $image['cloudinary_public_id'] . "'"); } $objEvent = new CEventPhoto('LegacysoapController', 'onFlushTable', null, null, 0); _xls_raise_events('CEventPhoto', $objEvent); $strTableName = "xlsws_images"; break; } //Then truncate the table Yii::app()->db->createCommand()->truncateTable($strTableName); Yii::app()->db->createCommand('SET FOREIGN_KEY_CHECKS=1;')->execute(); return self::OK; }
/** * If any custom functions have been defined to run after completion process, attempt to run here * * @param $strOrderId WO-xxxxxx ID of an order */ protected static function runPostFinalizeHooks($strOrderId) { $objEvent = new CEventOrder('CartController', 'onCreateOrder', $strOrderId); _xls_raise_events('CEventOrder', $objEvent); return; }
public function onActionListOrderDetails($event) { Yii::log("Running event " . print_r($event, true), 'info', 'application.' . __CLASS__ . "." . __FUNCTION__); $data_id = $event->data_id; $arrData = explode(",", $data_id); $cartId = $arrData[0]; $checkDate = $arrData[1]; $config = array('ServiceURL' => $this->getMWSUrl() . "/Orders/" . $checkDate, 'ProxyHost' => null, 'ProxyPort' => -1, 'MaxErrorRetry' => 3); $service = new MarketplaceWebServiceOrders_Client($this->MWS_ACCESS_KEY_ID, $this->MWS_SECRET_ACCESS_KEY, $this->APPLICATION_NAME, $this->APPLICATION_VERSION, $config); $request = new MarketplaceWebServiceOrders_Model_ListOrderItemsRequest(); $request->setSellerId($this->MerchantID); $request->setAmazonOrderId($cartId); // object or array of parameters $response = $this->invokeListOrderItems($service, $request); $listOrderItemsResult = $response->getListOrderItemsResult(); if ($listOrderItemsResult->isSetOrderItems()) { $objCart = Cart::LoadByIdStr($cartId); if ($objCart->cart_type == CartType::cart) { $orderItems = $listOrderItemsResult->getOrderItems(); $orderItemList = $orderItems->getOrderItem(); $shippingCost = 0; foreach ($orderItemList as $orderItem) { $strCode = $orderItem->getSellerSKU(); Yii::log("Amazon " . $cartId . " item on order " . $strCode, 'info', 'application.' . __CLASS__ . "." . __FUNCTION__); Yii::log("Order item information " . print_r($orderItem, true), 'info', 'application.' . __CLASS__ . "." . __FUNCTION__); $intQty = $orderItem->getQuantityOrdered(); $objPrice = $orderItem->getItemPrice(); $fltPrice = $objPrice->getAmount(); $strCurrency = $objPrice->getCurrencyCode(); //Amazon provides price as total for line item, but our AddToCart expects per item //so we divide if ($intQty > 1) { $fltPrice = $fltPrice / $intQty; } if ($orderItem->isSetShippingPrice()) { $objShippingPrice = $orderItem->getShippingPrice(); if ($objShippingPrice->isSetAmount()) { $shippingCost += $objShippingPrice->getAmount(); } } if ($orderItem->isSetPromotionDiscount()) { $promotionDiscount = $orderItem->getPromotionDiscount(); $fltDiscount = $promotionDiscount->getAmount(); } else { $fltDiscount = 0; } $objProduct = Product::LoadByCode($strCode); if (is_null($objProduct)) { $objCart->printed_notes .= "ERROR MISSING PRODUCT - " . "Attempted to download a product from Amazon " . $strCode . " that doesn't exist in Web Store\n"; Yii::log("Attempted to download a product from Amazon " . $strCode . " that doesn't exist in Web Store", 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); } else { $objCart->AddProduct($objProduct, $intQty, CartType::order, null, $orderItem->getTitle(), $fltPrice, $fltDiscount); } $objCart->currency = $strCurrency; if (!$objCart->save()) { Yii::log("Error saving cart " . print_r($objCart->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); } } $objCart->cart_type = CartType::order; if (!$objCart->save()) { Yii::log("Error saving cart " . print_r($objCart->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); } $objShipping = $objCart->shipping; $objShipping->shipping_cost = $shippingCost; $objShipping->shipping_sell = $shippingCost; $objShipping->save(); $objCart->recalculateAndSave(); $objCart->RecalculateInventoryOnCartItems(); //A new order has been created, so run signal $objEvent = new CEventOrder('wsamazon', 'onCreateOrder', $objCart->id_str); _xls_raise_events('CEventOrder', $objEvent); } } return self::SUCCESS; }
/** For any cart items, recalculate the inventory available. Always needs to be done after * an order is completed * */ public function RecalculateInventoryOnCartItems() { $arrItems = $this->cartItems; foreach ($arrItems as $objItem) { $objItem->product->SetAvailableInventory(); foreach ($objItem->product->xlswsCategories as $objCategory) { $objCategory->UpdateChildCount(); } // Since products belong to one family we can call updateChildCount on the // product's family if (is_null($objItem->product->family) === false) { $objItem->product->family->UpdateChildCount(); } $objEvent = new CEventProduct(get_class($this), 'onUpdateInventory', $objItem->product); _xls_raise_events('CEventProduct', $objEvent); } }
/** * Process manual payment on admin panel * * @param $objCart * @param $objCartPayment * @return string 'success' or error messages from the models */ public static function processManualPayment($objCart, $objCartPayment) { $objCart->setScenario('manual'); $objCartPayment->setScenario('manual'); $objCart->attributes = $_POST['Cart']; $objCartPayment->attributes = $_POST['CartPayment']; switch ($objCart->cart_type) { case CartType::order: $objCart->status = OrderStatus::AwaitingProcessing; $objCartPayment->payment_status = OrderStatus::Completed; $objCartPayment->datetime_posted = new CDbExpression('NOW()'); break; case CartType::awaitpayment: $objCart->status = OrderStatus::AwaitingPayment; $objCartPayment->payment_status = NULL; $objCartPayment->datetime_posted = NULL; break; } if ($objCart->validate() && $objCartPayment->validate()) { $objCart->save(); $objCartPayment->save(); $objEvent = new CEventOrder('CartController', 'onCreateOrder', $objCart->id_str); _xls_raise_events('CEventOrder', $objEvent); return "success"; } else { return implode(" ", _xls_convert_errors($objCart->getErrors() + $objCartPayment->getErrors())); } }
public function saveProductImage($intRowid, $image_index, $imageId = null) { $objProduct = Product::model()->findByPk($intRowid); if (!$objProduct instanceof Product) { Yii::log('Product Id does not exist ' . $intRowid, 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); return false; } //Create event $objEvent = new CEventPhoto('LegacysoapController', 'onUploadPhoto', null, $objProduct, $image_index); $objEvent->cloud_image_id = $imageId; if (isset($_SERVER['HTTP_CLOUDINARY_PUBLIC_ID'])) { $objEvent->cloudinary_public_id = $_SERVER['HTTP_CLOUDINARY_PUBLIC_ID']; } if (isset($_SERVER['HTTP_CLOUDINARY_NAME'])) { $objEvent->cloudinary_cloud_name = $_SERVER['HTTP_CLOUDINARY_NAME']; } if (isset($_SERVER['HTTP_CLOUDINARY_VERSION'])) { $objEvent->cloudinary_version = $_SERVER['HTTP_CLOUDINARY_VERSION']; } _xls_raise_events('CEventPhoto', $objEvent); return true; }
/** * If any custom functions have been defined to run after completion process, attempt to run here * @param $objCart * @return mixed */ protected static function PostFinalizeHooks($objCart) { $objEvent = new CEventOrder('CartController', 'onCreateOrder', $objCart->id_str); _xls_raise_events('CEventOrder', $objEvent); return $objCart; }