public function storeProduct($data, $category) { if ($category == "laptop") { $product_info = array('title' => isset($data['title']) ? $data['title'] : "", 'price' => isset($data['price']) ? $data['price'] : "", 'cash_on_delivery' => "yes", 'in_the_box_details' => isset($data['sales_package']) ? $data['sales_package'] : "", 'model_name' => isset($data['model_name']) ? $data['model_name'] : "", 'series_name' => isset($data['series']) ? $data['series'] : "", 'color' => isset($data['color']) ? $data['color'] : "", 'part_number' => isset($data['part_number']) ? $data['part_number'] : "", 'model_id' => isset($data['model_id']) ? $data['model_id'] : "", 'warranty' => isset($data['warranty_summary']) ? $data['warranty_summary'] : "", 'brand_name' => isset($data['brand']) ? $data['brand'] : "", 'category_name' => $category, 'country_name' => "India", 'product_code' => isset($data['product_code']) ? $data['product_code'] : "", 'video_url' => isset($data['video_url']) ? $data['video_url'] : "", 'star_rate' => isset($data['star_rate']) ? $data['star_rate'] : "", 'lifestyle_name' => isset($data['lifestyle']) ? $data['lifestyle'] : "", 'hardware_interface' => isset($data['hardware_interface']) ? $data['hardware_interface'] : "", 'other_ports' => isset($data['other_ports']) ? $data['other_ports'] : "", 'chipset' => isset($data['chipset']) ? $data['chipset'] : "", 'system_architecture' => isset($data['system_architecture']) ? $data['system_architecture'] : ""); } else { if ($category == "mobile") { $product_info = array('title' => isset($data['title']) ? $data['title'] : "", 'price' => isset($data['price']) ? $data['price'] : "", 'cash_on_delivery' => "yes", 'in_the_box_details' => isset($data['sales_package']) ? $data['sales_package'] : "", 'series_name' => isset($data['series']) ? $data['series'] : "", 'color' => isset($data['handset_color']) ? $data['handset_color'] : "", 'part_number' => isset($data['part_number']) ? $data['part_number'] : "", 'model_id' => isset($data['model_id']) ? $data['model_id'] : "", 'warranty' => isset($data['warranty_summary']) ? $data['warranty_summary'] : "", 'brand_name' => isset($data['brand']) ? $data['brand'] : "", 'category_name' => $category, 'country_name' => "India", 'product_code' => isset($data['product_code']) ? $data['product_code'] : "", 'video_url' => isset($data['video_url']) ? $data['video_url'] : "", 'star_rate' => isset($data['star_rate']) ? $data['star_rate'] : "", 'lifestyle_name' => isset($data['lifestyle']) ? $data['lifestyle'] : "", 'java' => isset($data['java']) ? $data['java'] : "", 'sar_value' => isset($data['sar_value']) ? $data['sar_value'] : "", 'hot_swap_support' => isset($data['hot_swap_support']) ? $data['hot_swap_support'] : ""); } } $model = new Product(); $model->attributes = $product_info; $filename = str_replace('/', '_', $data['title']) . "200x200_medium_0.jpeg"; $filename = str_replace(' ', "_", $filename); $model->image = $filename; if ($model->save()) { /* echo "<pre>"; print_r($data); echo "</pre>"; echo "<pre>"; print_r($model->attributes); echo "</pre>"; */ echo "<li>" . $data['title'] . "-<b>Saved</b></li>"; if ($category == "laptop") { if ($model->saveLaptopFeatures($data)) { $model->associateWithStore($data, "flipkart"); $model->saveImages($data); $model->ready_to_export = 1; $model->save(false); } else { echo "Err-saving Laptop features."; } } else { if ($category == "mobile") { if ($model->saveMobileFeatures($data)) { $model->associateWithStore($data, "flipkart"); $model->saveImages($data); $model->ready_to_export = 1; $model->save(false); } else { echo "Err-saving Mobile features."; } } } /* echo "<pre>"; print_r($model->attributes); echo "</pre>"; */ /* if(!$model->saveImages($data)) { return(false); } */ } else { Yii::app()->db->createCommand("update product set price='" . $data['price'] . "' where product_code='" . $data['product_code'] . "' ")->execute(); echo "ERR-SAVING product"; $e = $model->getErrors(); echo "<pre>"; print_r($e); echo "</pre>"; return false; } flush(); return true; }
/** * Save a product in the database (Create if need be) * * @param string $passkey * @param int $intRowid * @param string $strCode * @param string $strName * @param string $blbImage * @param string $strClassName * @param int $blnCurrent * @param string $strDescription * @param string $strDescriptionShort * @param string $strFamily * @param int $blnGiftCard * @param int $blnInventoried * @param double $fltInventory * @param double $fltInventoryTotal * @param int $blnMasterModel * @param int $intMasterId * @param string $strProductColor * @param string $strProductSize * @param double $fltProductHeight * @param double $fltProductLength * @param double $fltProductWidth * @param double $fltProductWeight * @param int $intTaxStatusId * @param double $fltSell * @param double $fltSellTaxInclusive * @param double $fltSellWeb * @param string $strUpc * @param int $blnOnWeb * @param string $strWebKeyword1 * @param string $strWebKeyword2 * @param string $strWebKeyword3 * @param int $blnFeatured * @param string $strCategoryPath * @return string */ public function save_product($passkey, $intRowid, $strCode, $strName, $blbImage, $strClassName, $blnCurrent, $strDescription, $strDescriptionShort, $strFamily, $blnGiftCard, $blnInventoried, $fltInventory, $fltInventoryTotal, $blnMasterModel, $intMasterId, $strProductColor, $strProductSize, $fltProductHeight, $fltProductLength, $fltProductWidth, $fltProductWeight, $intTaxStatusId, $fltSell, $fltSellTaxInclusive, $fltSellWeb, $strUpc, $blnOnWeb, $strWebKeyword1, $strWebKeyword2, $strWebKeyword3, $blnFeatured, $strCategoryPath) { if (!$this->check_passkey($passkey)) { return self::FAIL_AUTH; } // We must preservice the Rowid of Products within the Web Store // database and must therefore see if it already exists $objProduct = Product::model()->findByPk($intRowid); if (!$objProduct) { $objProduct = new Product(); $objProduct->id = $intRowid; } $strName = trim($strName); $strName = trim($strName, '-'); $strName = substr($strName, 0, 255); $strCode = trim($strCode); $strCode = str_replace('"', '', $strCode); $strCode = str_replace("'", '', $strCode); if (empty($strName)) { $strName = 'missing-name'; } if (empty($strDescription)) { $strDescription = ''; } $objProduct->code = $strCode; $objProduct->title = $strName; //$objProduct->class_name = $strClassName; $objProduct->current = $blnCurrent; $objProduct->description_long = $strDescription; $objProduct->description_short = $strDescriptionShort; //$objProduct->family = $strFamily; $objProduct->gift_card = $blnGiftCard; $objProduct->inventoried = $blnInventoried; $objProduct->inventory = $fltInventory; $objProduct->inventory_total = $fltInventoryTotal; $objProduct->master_model = $blnMasterModel; if ($intMasterId > 0) { $objProduct->parent = $intMasterId; } else { $objProduct->parent = null; } $objProduct->product_color = $strProductColor; $objProduct->product_size = $strProductSize; $objProduct->product_height = $fltProductHeight; $objProduct->product_length = $fltProductLength; $objProduct->product_width = $fltProductWidth; $objProduct->product_weight = $fltProductWeight; $objProduct->tax_status_id = $intTaxStatusId; $objProduct->sell = $fltSell; $objProduct->sell_tax_inclusive = $fltSellTaxInclusive; //If we're in TaxIn Mode, then SellWeb has tax and we reverse it. if (_xls_get_conf('TAX_INCLUSIVE_PRICING', 0) == 1) { if ($fltSellWeb != 0) { //Tax in with a sell on web price $objProduct->sell_web_tax_inclusive = $fltSellWeb; //LS sends tax in web already $objProduct->sell_web = Tax::StripTaxesFromPrice($fltSellWeb, $intTaxStatusId); } else { //We use our regular prices and copy them price $objProduct->sell_web_tax_inclusive = $fltSellTaxInclusive; $objProduct->sell_web = $fltSell; } } else { if ($fltSellWeb != 0) { $objProduct->sell_web = $fltSellWeb; } else { $objProduct->sell_web = $fltSell; } } $objProduct->upc = $strUpc; $objProduct->web = $blnOnWeb; $objProduct->featured = $blnFeatured; $fltReserved = $objProduct->CalculateReservedInventory(); $objProduct->inventory_reserved = $fltReserved; if (Yii::app()->params['INVENTORY_FIELD_TOTAL'] == 1) { $objProduct->inventory_avail = $fltInventoryTotal - $fltReserved; } else { $objProduct->inventory_avail = $fltInventory - $fltReserved; } //Because Lightspeed may send us products out of sequence (child before parent), we have to turn this off Yii::app()->db->createCommand('SET FOREIGN_KEY_CHECKS=0;')->execute(); if (!$objProduct->save()) { Yii::log("SOAP ERROR : Error saving product {$intRowid} {$strCode} " . print_r($objProduct->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); return self::UNKNOWN_ERROR . " Error saving product {$intRowid} {$strCode} " . print_r($objProduct->getErrors(), true); } $strFeatured = _xls_get_conf('FEATURED_KEYWORD', 'XnotsetX'); if (empty($strFeatured)) { $strFeatured = 'XnotsetX'; } //Save keywords $strTags = trim($strWebKeyword1) . "," . trim($strWebKeyword2) . "," . trim($strWebKeyword3); $strTags = str_replace(",,", ",", $strTags); $arrTags = explode(",", $strTags); ProductTags::DeleteProductTags($objProduct->id); foreach ($arrTags as $indivTag) { if (!empty($indivTag)) { $tag = Tags::model()->findByAttributes(array('tag' => $indivTag)); if (!$tag instanceof Tags) { $tag = new Tags(); $tag->tag = $indivTag; $tag->save(); } $objProductTag = new ProductTags(); $objProductTag->product_id = $objProduct->id; $objProductTag->tag_id = $tag->id; $objProductTag->save(); if ($strFeatured != 'XnotsetX' && $objProduct->web && $indivTag == $strFeatured) { $objProduct->featured = 1; $objProduct->save(); } } } if (!empty($strFamily)) { $objFamily = Family::model()->findByAttributes(array('family' => $strFamily)); if ($objFamily instanceof Family) { $objProduct->family_id = $objFamily->id; $objProduct->save(); } else { $objFamily = new Family(); $objFamily->family = $strFamily; $objFamily->child_count = 0; $objFamily->request_url = _xls_seo_url($strFamily); $objFamily->save(); $objProduct->family_id = $objFamily->id; $objProduct->save(); } $objFamily->UpdateChildCount(); } else { if ($objProduct->family_id) { $objFamily = Family::model()->findByAttributes(array('id' => $objProduct->family_id)); $objProduct->family_id = null; $objProduct->save(); $objFamily->UpdateChildCount(); } } if (!empty($strClassName)) { $objClass = Classes::model()->findByAttributes(array('class_name' => $strClassName)); if ($objClass instanceof Classes) { $objProduct->class_id = $objClass->id; $objProduct->save(); } else { $objClass = new Classes(); $objClass->class_name = $strClassName; $objClass->child_count = 0; $objClass->request_url = _xls_seo_url($strClassName); $objClass->save(); $objProduct->class_id = $objClass->id; $objProduct->save(); } $objClass->UpdateChildCount(); } // Save category $strCategoryPath = trim($strCategoryPath); if ($strCategoryPath && $strCategoryPath != "Default") { $arrCategories = explode("\t", $strCategoryPath); $intCategory = Category::GetIdByTrail($arrCategories); if (!is_null($intCategory)) { $objCategory = Category::model()->findByPk($intCategory); //Delete any prior categories from the table ProductCategoryAssn::model()->deleteAllByAttributes(array('product_id' => $objProduct->id)); $objAssn = new ProductCategoryAssn(); $objAssn->product_id = $objProduct->id; $objAssn->category_id = $intCategory; $objAssn->save(); $objCategory->UpdateChildCount(); } } else { ProductCategoryAssn::model()->deleteAllByAttributes(array('product_id' => $objProduct->id)); } Product::convertSEO($intRowid); //Build request_url Yii::app()->db->createCommand('SET FOREIGN_KEY_CHECKS=1;')->execute(); $objEvent = new CEventProduct('LegacysoapController', 'onSaveProduct', $objProduct); _xls_raise_events('CEventProduct', $objEvent); // return self::OK; }
public function actionWrite() { if (isset($_POST['Product'])) { $messages = $this->ValidateData(array(array($_POST['Product']['productname'], 'emptyproductname', 'emptystring'))); if ($messages == '') { if ((int) $_POST['Product']['productid'] > 0) { $model = Product::model()->findbyPK($_POST['Product']['productid']); $model->productname = $_POST['Product']['productname']; $model->isstock = $_POST['Product']['isstock']; $model->recordstatus = $_POST['Product']['recordstatus']; } else { $model = new Product(); $model->attributes = $_POST['Product']; } try { if ($model->save()) { $this->DeleteLock($this->menuname, $_POST['Product']['productname']); $this->GetSMessage('insertsuccess'); } else { $this->GetMessage($model->getErrors()); } } catch (Exception $e) { $this->GetMessage($e->getMessage()); } } } }
public static function editProduct($params) { $resultInfo = array(); $connection = Yii::app()->db; $transaction = $connection->beginTransaction(); $actionType = BugfreeModel::ACTION_OPEN; $oldRecordAttributs = array(); if (isset($params['id'])) { $product = self::loadModel((int) $params['id']); $oldRecordAttributs = $product->attributes; $oldRecordAttributs['product_manager'] = $product->product_manager; if (!empty($product->group_name)) { $oldRecordAttributs['group_name'] = join(',', $product->group_name); } $actionType = BugfreeModel::ACTION_EDIT; } else { $product = new Product(); } if (!ProductService::isProductEditable($product['id'])) { $resultInfo['status'] = CommonService::$ApiResult['FAIL']; $resultInfo['detail']['id'] = Yii::t('Common', 'Required URL not found or permission denied.'); return $resultInfo; } try { $product->attributes = $params; if (!$product->save()) { $resultInfo['status'] = CommonService::$ApiResult['FAIL']; $resultInfo['detail'] = $product->getErrors(); } else { Yii::app()->db->createCommand()->delete('{{map_product_group}}', 'product_id=:productId', array(':productId' => $product->id)); if (!empty($params['group_name'])) { foreach ($params['group_name'] as $groupId) { $mapProductGroup = new MapProductGroup(); $mapProductGroup->product_id = $product->id; $mapProductGroup->user_group_id = $groupId; $mapProductGroup->save(); } } Yii::app()->db->createCommand()->delete('{{map_product_user}}', 'product_id=:productId', array(':productId' => $product->id)); if ('' != trim($params['product_manager'])) { $managerNameArr = CommonService::splitStringToArray(",", $params['product_manager']); foreach ($managerNameArr as $managerName) { $userInfo = TestUser::model()->findByAttributes(array('realname' => $managerName, 'is_dropped' => CommonService::$TrueFalseStatus['FALSE'])); if ($userInfo !== null) { $mapProductUser = new MapProductUser(); $mapProductUser->product_id = $product->id; $mapProductUser->test_user_id = $userInfo->id; $mapProductUser->save(); } else { $resultInfo['status'] = CommonService::$ApiResult['FAIL']; $resultInfo['detail'] = array('product_manager' => '[' . $managerName . ']' . Yii::t('TestUser', self::ERROR_USER_NOT_FOUND)); return $resultInfo; } } } $newRecord = self::loadModel($product->id); if (!empty($newRecord->group_name)) { $newRecord->group_name = join(',', $newRecord->group_name); } $addActionResult = AdminActionService::addActionNotes('product', $actionType, $newRecord, $oldRecordAttributs); if (!isset($params['id'])) { FieldConfigService::createAddOnTable($product->id); } $transaction->commit(); $resultInfo['status'] = CommonService::$ApiResult['SUCCESS']; $resultInfo['detail'] = array('id' => $product->id); } return $resultInfo; } catch (Exception $e) { $transaction->rollBack(); $resultInfo['status'] = CommonService::$ApiResult['FAIL']; $resultInfo['detail']['id'] = $e->getMessage(); } return $resultInfo; }
function deleteAction() { $id = AF::get($_POST, 'id', 0); $modelsID = explode(',', $id); $errors = FALSE; foreach ($modelsID as $id) { $model = new Product(); $model->model_uset_id = $this->user->user_id; if ($model->findByPk($id)) { $model->delete($id); } else { $errors = TRUE; } if ($model->getErrors()) { $errors = TRUE; } unset($model); } if (isset($_POST['ajax'])) { AF::setJsonHeaders('json'); if ($errors) { Message::echoJsonError(__('product_no_deleted')); } else { $countE = AF::get($_POST, 'countE', 100000); if (count($modelsID) >= $countE) { $link = AF::link(array('products' => 'view')); Message::echoJsonRedirect($link); } else { Message::echoJsonSuccess(__('product_deleted')); } } } $this->redirect(); }