/** * Returns an singleton instance of this class * * @param object $config * @param object $args * @return */ public static function getInstance($config, $args) { if (self::$instance == null) { self::$instance = new ImportItemsTempManager($config, $args); } return self::$instance; }
public function load() { $company_id = $_REQUEST['company_id']; $used_columns_indexes_array = array(2, 1, 9, 3, 4, 5, 6, 7); //explode(',', $_REQUEST['used_columns_indexes']); $importItemsTempManager = ImportItemsTempManager::getInstance($this->config, $this->args); $categoryHierarchyManager = CategoryHierarchyManager::getInstance($this->config, $this->args); $categoryManager = CategoryManager::getInstance($this->config, $this->args); $customerLogin = $this->getCustomerLogin(); $priceRowsDtos = $importItemsTempManager->getUserCurrentPriceChangedRows($customerLogin); $columnNames = ImportPriceManager::getColumnNamesMap($used_columns_indexes_array); $rootDto = $categoryManager->getRoot(); $firstLevelCategoriesHierarchyDtos = $categoryHierarchyManager->getCategoryChildren($rootDto->getId()); $firstLevelCategoriesNamesDtos = $categoryHierarchyManager->getCategoriesNamesByParentCategoryId($rootDto->getId()); $firstLevelCategoriesIds = array(); foreach ($firstLevelCategoriesHierarchyDtos as $key => $category) { $firstLevelCategoriesIds[] = $category->getChildId(); } $firstLevelCategoriesNames = array(); foreach ($firstLevelCategoriesNamesDtos as $key => $category) { $firstLevelCategoriesNames[] = $category->getDisplayName(); } $itemManager = ItemManager::getInstance($this->config, $this->args); $companyAllItems = $itemManager->getCompanyItems($company_id, true); $convertDtosArrayToArrayMapById = $this->convertDtosArrayToArrayMapById($companyAllItems); $this->addParam('stockItemsDtosMappedByIds', $convertDtosArrayToArrayMapById); $this->addParam('columnNames', $columnNames); $this->addParam('priceRowsDtos', $priceRowsDtos); $this->addParam('firstLevelCategoriesNames', $firstLevelCategoriesNames); $this->addParam('firstLevelCategoriesIds', $firstLevelCategoriesIds); list($changedRowIds, $changedFields) = $this->findChanges($priceRowsDtos, $convertDtosArrayToArrayMapById, $columnNames); $this->addParam('changedRowsIds', $changedRowIds); $this->addParam('changedFields', $changedFields); }
public function load() { //new items import level $company_id = $_REQUEST['company_id']; $used_columns_indexes_array = array(2, 1, 9, 3, 4, 5, 6, 7); //explode(',', $_REQUEST['used_columns_indexes']); $importItemsTempManager = ImportItemsTempManager::getInstance($this->config, $this->args); $categoryHierarchyManager = CategoryHierarchyManager::getInstance($this->config, $this->args); $categoryManager = CategoryManager::getInstance($this->config, $this->args); $customerLogin = $this->getCustomerLogin(); $priceRowsDtos = $importItemsTempManager->getUserCurrentPriceNewRows($customerLogin); foreach ($priceRowsDtos as $dto) { $itemModel = $dto->getModel(); if (empty($itemModel)) { $model = $importItemsTempManager->findModelFromItemTitle($dto->getDisplayName()); if (!empty($model)) { $dto->setSupposedModel($model); } } else { $dto->setSupposedModel($itemModel); } } $columnNames = ImportPriceManager::getColumnNamesMap($used_columns_indexes_array); $rootDto = $categoryManager->getRoot(); $firstLevelCategoriesHierarchyDtos = $categoryHierarchyManager->getCategoryChildren($rootDto->getId()); $firstLevelCategoriesNamesDtos = $categoryHierarchyManager->getCategoriesNamesByParentCategoryId($rootDto->getId()); $firstLevelCategoriesIds = array(); foreach ($firstLevelCategoriesHierarchyDtos as $key => $category) { $firstLevelCategoriesIds[] = $category->getChildId(); } $firstLevelCategoriesNames = array(); foreach ($firstLevelCategoriesNamesDtos as $key => $category) { $firstLevelCategoriesNames[] = $category->getDisplayName(); } $this->addParam('columnNames', $columnNames); $this->addParam('priceRowsDtos', $priceRowsDtos); $this->addParam('firstLevelCategoriesNames', $firstLevelCategoriesNames); $this->addParam('firstLevelCategoriesIds', $firstLevelCategoriesIds); if (isset($_REQUEST['new_items_row_ids'])) { $this->addParam('new_items_row_ids', explode(',', $_REQUEST['new_items_row_ids'])); } //$json_parsed_price = $_REQUEST['json_parsed_price']; //$parsed_price_array = json_decode($json_parsed_price); /* $companyItems = $itemManager->getCompanyItems($company_id, true); $stockItemModels = array(); $stockItemNames = array(); $stockItemDealerPrices = array(); $stockItemVatPrices = array(); $stockItemIsHidden = array(); foreach ($companyItems as $itemDto) { $stockItemModels[] = } */ }
public function load() { ini_set('max_execution_time', '120'); $itemManager = ItemManager::getInstance($this->config, $this->args); $importItemsTempManager = ImportItemsTempManager::getInstance($this->config, $this->args); $importPriceManager = ImportPriceManager::getInstance($this->config, $this->args); $company_id = $_REQUEST['company_id']; $selectSheetIndex = intval($_REQUEST['sheet_index']); $selectPriceIndex = intval($_REQUEST['price_index']); if (!isset($_REQUEST['aceptable_simillarity_percent'])) { $acepableItemSimillarityPercent = 50; } else { $acepableItemSimillarityPercent = intval($_REQUEST['aceptable_simillarity_percent']); } $this->addParam('company_id', $company_id); $this->addParam('acepableItemSimillarityPercent', $acepableItemSimillarityPercent); $this->addParam('acepableItemSimillarityPercentOptions', array('20', '25', '30', '35', '40', '45', '50', '55', '60', '65', '70', '75', '80', '85', '90')); $customerLogin = $this->getCustomerLogin(); $used_columns_indexes_array = explode(',', $_REQUEST['used_columns_indexes']); $this->addParam('used_columns_indexes_array', implode(',', $used_columns_indexes_array)); if (!(isset($_REQUEST['dont_recalculate']) && $_REQUEST['dont_recalculate'] == 1)) { $values = $importPriceManager->loadCompanyPriceFromCache($company_id, $selectPriceIndex, $selectSheetIndex); $importItemsTempManager->deleteCustomerRows($customerLogin); $used_columns_ids_array = explode(',', $_REQUEST['used_columns_ids']); $selected_rows_index = array(); //following strlen is important to accept "0" value if (isset($_REQUEST['selected_rows_index']) && strlen($_REQUEST['selected_rows_index']) > 0) { $selected_rows_index = explode(',', $_REQUEST['selected_rows_index']); } // $itemNamesArray = array(); // foreach ($values as $index => $row) { // if (!in_array($index, $selected_rows_index)) { // continue; // } // $nameColumn = ""; // foreach ($used_columns_ids_array as $key => $cellId) { // if ($used_columns_indexes_array[$key] == 2) { // $nameColumn .= ($row[$cellId] . ' '); // } // } // $itemNamesArray[$index] = $nameColumn; // } // $keys = array_keys($itemNamesArray); // $itemNames = implode('!@<>?$#|', $itemNamesArray); // $itemNames = LanguageManager::translateItemDisplayNameNonEnglishWordsToEnglish($itemNames); // $itemNames = preg_replace('/[^(\x20-\x7F)]*/', '', $itemNames); // if (count($keys) > 0) { // $itemNamesArray = explode('!@<>?$#|', $itemNames); // } else { // $itemNamesArray = array(); // } // $itemNamesArray = array_combine($keys, $itemNamesArray); $brand_model_name_concat_method = $_REQUEST['brand_model_name_concat_method']; $priceTranslationsManager = PriceTranslationsManager::getInstance($this->config, $this->args); foreach ($values as $index => $row) { if (!in_array($index, $selected_rows_index)) { continue; } $nameColumn = ""; foreach ($used_columns_ids_array as $key => $cellId) { if ($used_columns_indexes_array[$key] == 1) { $modelColumn = $row[$cellId]; } if ($used_columns_indexes_array[$key] == 2) { $nameColumn .= $priceTranslationsManager->translateItemDisplayNameNonEnglishWordsToEnglish($row[$cellId]) . ' '; $nameColumn = preg_replace('/[^(\\x20-\\x7F)]*/', '', $nameColumn); } if ($used_columns_indexes_array[$key] == 3) { $dealerPriceColumn = $row[$cellId]; } if ($used_columns_indexes_array[$key] == 4) { $dealerPriceAmdColumn = $row[$cellId]; } if ($used_columns_indexes_array[$key] == 5) { $vatPriceColumn = $row[$cellId]; } if ($used_columns_indexes_array[$key] == 6) { $vatPriceAmdColumn = $row[$cellId]; } if ($used_columns_indexes_array[$key] == 7) { $warrantyMonthColumn = $row[$cellId]; } if ($used_columns_indexes_array[$key] == 8) { $warrantyYearColumn = $row[$cellId]; } if ($used_columns_indexes_array[$key] == 9) { $brandColumn = $row[$cellId]; } } if ($brand_model_name_concat_method === 'bmn') { $nameColumn = $brandColumn . ' ' . $modelColumn . ' ' . $nameColumn; } elseif ($brand_model_name_concat_method === 'bn') { $nameColumn = $brandColumn . ' ' . $nameColumn; } elseif ($brand_model_name_concat_method === 'mn') { $nameColumn = $modelColumn . ' ' . $nameColumn; } $importItemsTempManager->addRow($customerLogin, $modelColumn, $nameColumn, $dealerPriceColumn, $dealerPriceAmdColumn, $vatPriceColumn, $vatPriceAmdColumn, $warrantyMonthColumn, $warrantyYearColumn, $brandColumn); } } $priceRowsDtos = $importItemsTempManager->getUserCurrentRows($customerLogin); $columnNames = $importPriceManager->getColumnNamesMap($used_columns_indexes_array); $this->addParam('columnNames', $columnNames); $companyAllItems = $itemManager->getCompanyItems($company_id, true); $convertDtosArrayToArrayMapById = $this->convertDtosArrayToArrayMapById($companyAllItems); $this->addParam('stockItemsDtosMappedByIds', $convertDtosArrayToArrayMapById); //$t = microtime(true); if (!(isset($_REQUEST['dont_recalculate']) && $_REQUEST['dont_recalculate'] == 1)) { $stockAndPriceItemsMatchingMap = $this->getStockAndPriceItemsMatchingMap($priceRowsDtos, $companyAllItems, $acepableItemSimillarityPercent); $cycleCount = 0; while ($this->getStockAndPriceItemsMatchingMap($priceRowsDtos, $companyAllItems, $acepableItemSimillarityPercent, true, $stockAndPriceItemsMatchingMap)) { $cycleCount++; } foreach ($stockAndPriceItemsMatchingMap as $stockItemId => $priceItemIdAndSimilarPercentPairArray) { $rowId = $priceItemIdAndSimilarPercentPairArray[0]; $importItemsTempManager->setMatchedItemId($rowId, $stockItemId); $shortSpec = $convertDtosArrayToArrayMapById[$stockItemId]->getShortDescription(); $fullSpec = $convertDtosArrayToArrayMapById[$stockItemId]->getFullDescription(); $importItemsTempManager->updateTextField($rowId, 'short_spec', $shortSpec); $importItemsTempManager->updateTextField($rowId, 'full_spec', $fullSpec); } } $priceRowsDtos = $importItemsTempManager->getUserCurrentRows($customerLogin); //getting metched stock items ids $matchedStockItemIdsArray = array(); foreach ($priceRowsDtos as $priceRowDto) { $matchedItemId = $priceRowDto->getMatchedItemId(); if (intval($matchedItemId) > 0) { $matchedStockItemIdsArray[] = intval($matchedItemId); } } //getting company items which are not matched to any item in price table $unmatchedCompanyStockItems = array(); foreach ($companyAllItems as $stockItemDto) { $itemId = intval($stockItemDto->getId()); if (!in_array($itemId, $matchedStockItemIdsArray)) { $unmatchedCompanyStockItems[$itemId] = $stockItemDto; } } $this->addParam('unmatchedCompanyItems', $unmatchedCompanyStockItems); $this->addParam('priceRowsDtos', $priceRowsDtos); $this->addParam('matched_price_items_count', count($stockAndPriceItemsMatchingMap)); $this->addParam('unmatched_price_items_count', count($priceRowsDtos) - count($stockAndPriceItemsMatchingMap)); }
public function service() { $action = $_REQUEST['action']; $importItemsTempManager = ImportItemsTempManager::getInstance($this->config, $this->args); switch ($action) { case 'step_1_unbind_price_row': $price_item_id = $_REQUEST['price_item_id']; $importItemsTempManager->setMatchedItemId($price_item_id, 0); $importItemsTempManager->updateTextField($price_item_id, 'short_spec', ''); $importItemsTempManager->updateTextField($price_item_id, 'full_spec', ''); $this->ok(); break; case 'step_1_link_stock_item_to_price_item': $price_item_id = $_REQUEST['price_item_id']; $stock_item_id = $_REQUEST['stock_item_id']; $importItemsTempManager->setMatchedItemId($price_item_id, $stock_item_id); $itemManager = ItemManager::getInstance($this->config, $this->args); $stockItem = $itemManager->selectByPK($stock_item_id); $importItemsTempManager->updateTextField($price_item_id, 'short_spec', $stockItem->getShortDescription()); $importItemsTempManager->updateTextField($price_item_id, 'full_spec', $stockItem->getFullDescription()); $this->ok(); break; case 'edit_cell_value': $cell_value = $_REQUEST['cell_value']; $field_name = $_REQUEST['field_name']; $pk_value = $_REQUEST['pk_value']; $importItemsTempManager->updateTextField($pk_value, $importItemsTempManager->getFieldKeyByFieldName($field_name), $cell_value); $dto = $importItemsTempManager->selectByPK($pk_value); $this->ok(array('cell_value' => $dto->{$field_name})); break; case 'import': $new_items_row_ids = $this->secure($_REQUEST['new_items_row_ids']); if (!empty($new_items_row_ids)) { $new_items_row_ids = explode(',', $new_items_row_ids); } else { $new_items_row_ids = array(); } $changed_rows_ids = $this->secure($_REQUEST['changed_rows_ids']); if (!empty($changed_rows_ids)) { $changed_rows_ids = explode(',', $changed_rows_ids); } else { $changed_rows_ids = array(); } list($newItemsCount, $updatedItemsCount) = $importItemsTempManager->importToItemsTable($this->getCustomerLogin(), $this->secure($_REQUEST['company_id']), $new_items_row_ids, $changed_rows_ids); $this->ok(array('new_items_count' => $newItemsCount, 'updated_items_count' => $updatedItemsCount)); break; case 'find_similar_items': $searchText = $this->secure($_REQUEST['search_text']); $itemManager = ItemManager::getInstance($this->config, $this->args); $itemsDtos = $itemManager->findSimillarItems($searchText, 10); $dtosToJSON = AbstractDto::dtosToJSON($itemsDtos); $this->ok(array('items' => $dtosToJSON)); break; case 'get_item_cat_spec': $item_id = intval($_REQUEST['item_id']); if ($item_id > 0) { $itemManager = ItemManager::getInstance($this->config, $this->args); $itemDto = $itemManager->selectByPK($item_id); $this->ok(array('short_description' => $itemDto->getShortDescription(), 'full_description' => $itemDto->getFullDescription(), 'categories_ids' => $itemDto->getCategoriesIds())); } else { $this->ok(array('short_description' => '', 'full_description' => '', 'categories_ids' => '')); } break; case 'upload_new_item_picture': $row_id = intval($_REQUEST['row_id']); $this->uploadNewIntemPicture($row_id); break; default: break; } }