//ignore header $line_of_text = fgetcsv($handle); while (!feof($handle)) { $line_of_text = fgetcsv($handle); if ($line_of_text) { array_push($stack, $line_of_text); } } fclose($handle); $count = count($stack); echo '<br>Count:' . $count; for ($i = 0; $i < $count; $i++) { $where = global_mapping::ArticleTypeID . '=' . $stack[$i][4] . ' and ' . global_mapping::PropertyGroupName . '=\'' . trim($stack[$i][1]) . '\''; $existedGroups = $objPropertyGroup->getAllPropertyGroup(0, '*', $where, ''); if (count($existedGroups) <= 0) { $groupID = $objPropertyGroup->insert($stack[$i][1], $stack[$i][1], $stack[$i][4], $i + 10, $createdBy); } else { $groupID = $existedGroups[0][0]; } $where = global_mapping::PropertyGroupID . '=' . $groupID . ' and ' . global_mapping::PropertyName . '=\'' . trim($stack[$i][0]) . '\''; $existedProperties = $objProperty->getAllProperty(0, '*', $where, ''); if (count($existedProperties) <= 0) { $objProperty->insert($groupID, $stack[$i][0], $stack[$i][2], 1, $stack[$i][3], $createdBy, 1); echo 'Inserted a new property ' . $stack[$i][0] . ' Group:' . $stack[$i][1] . 'Cat: ' . $stack[$i][4]; echo "<br>"; } else { echo 'Existed property ' . $stack[$i][0] . ' Group:' . $stack[$i][1] . 'Cat: ' . $stack[$i][4]; echo "<br>"; } //$stack[$i][4] = 1; }
if ($_pgR["act"] == Model_Product::ACT_ADD) { $createdBy = $c_userInfo[global_mapping::UserID]; $resultID = $objProduct->insert($productName, $catalogueID, $imageLink, $manufactoryID, $description, $createdBy, $status); if ($resultID) { $orderProductProperty = 0; $orderGroup = global_common::getMaxValueofField($objConnection, global_mapping::PropertyGroupID, Model_PropertyGroup::TBL_SL_PROPERTY_GROUP) + 1; foreach ($properties as $item) { $group = $item[global_mapping::PropertyGroupID]; $groupID = global_common::convertToInt($group); //is new group if ($groupID <= 0) { $searchGroup = $objPropertyGroup->getPropertyGroupByNameAndCat($group, $catalogueID); if ($searchGroup) { $groupID = $searchGroup[global_mapping::PropertyGroupID]; } else { $groupID = $objPropertyGroup->insert($group, $group, $catalogueID, $orderGroup, $createdBy, null); $orderGroup++; } } $propertyName = $item[global_mapping::PropertyID]; $propertyID = global_common::convertToInt($propertyName); //if is real propery name if ($propertyID <= 0) { $searchProperty = $objProperty->getPropertyByName($groupID, $propertyName); if ($searchProperty) { $propertyID = $searchProperty[global_mapping::PropertyID]; } else { $propertyID = $objProperty->insert($groupID, $propertyName, null, null, $createdBy, null); } } if ($propertyID) {
$objProperty = new Model_Property($objConnection); $objAdType = new Model_AdType($objConnection); $objDataType = new Model_Datatype($objConnection); $objPropertyGroup = new Model_PropertyGroup($objConnection); $allCats = $objArticleType->getAllArticleType(0, null, '', null); if ($_pgR["act"] == Model_PropertyGroup::ACT_ADD || $_pgR["act"] == Model_PropertyGroup::ACT_UPDATE) { //get user info $c_userInfo = $_SESSION[global_common::SES_C_USERINFO]; $propertyGroupName = $_pgR[global_mapping::PropertyGroupName]; $propertyGroupName = html_entity_decode($propertyGroupName, ENT_COMPAT, 'UTF-8'); $articleTypeID = html_entity_decode($_pgR[global_mapping::ArticleTypeID], ENT_COMPAT, 'UTF-8'); $order = html_entity_decode($_pgR[global_mapping::Order], ENT_COMPAT, 'UTF-8'); $status = 1; if ($_pgR["act"] == Model_PropertyGroup::ACT_ADD) { $createdBy = $c_userInfo[global_mapping::UserID]; $resultID = $objPropertyGroup->insert($propertyGroupName, $propertyGroupName, $articleTypeID, $order, $createdBy, $status); if ($resultID) { $arrHeader = global_common::getMessageHeaderArr($banCode); //$banCode echo global_common::convertToXML($arrHeader, array("rs", "inf"), array(1, 'Tạo mới thành công'), array(0, 1)); return; } else { echo global_common::convertToXML($arrHeader, array("rs", "inf"), array(0, "Input data is invalid"), array(0, 1)); return; } } else { $modifiedBy = $c_userInfo[global_mapping::UserID]; $propertyGroupID = html_entity_decode($_pgR[global_mapping::PropertyGroupID], ENT_COMPAT, 'UTF-8'); // $currentProperty = $objProperty->getPropertyByID($propertyID); $resultID = $objPropertyGroup->update($propertyGroupID, $propertyGroupName, $propertyGroupName, $articleTypeID, $order, $modifiedBy, $status); if ($resultID) {