Hallo,
ausgangslage .. habe ein csv bei dem die categorien in einem Produkt wie folgt aufgelistet sind:
dvds/filme/action/ab 18
hauptkategorie/unterkategorie/unterkategorie/unterkategorie/
jetzt wird das produkt nur angezeigt wenn man bis zur letzen kategorie klickt. wie kann ich den php-code im unicsvimport.php anpassen damit es entweder nur die ersten zwei kategorien einliest ( hauptkategorie/unterkategorie) und den rest nicht beachtet oder das es das produkt in jeder der kategorien anzeigt. sprich etwas aus dem dvds/filme/action/ab 18 folgendes automatisch macht dvds|dvds/filme|dvds/filme/action|dvds/filme/action/ab 18
leider kann ich das csv selbst nicht anpassen da von extern geladen.
denke die erste variante mit den nur haupt und erste unterkategorie laden wäre die einfachere und schnellere methode, jedoch weiss ich nicht genau wie ich einen stopp einfüge damit nach zwei kategorien gestoppt wird
wäre denke ich mal folgender Codeabschnitt verantwortlich
function _importCategories(&$prodArr, $pid, $updating) {
# If we edit product I insert new categories for him, i do not edit existing.
# Then I search categories with the same name as in import-data, and, if they exist I use them.
# Therefore later I make relationships as was before
# Indicates that some category (in any lang) is given in CSV
# (so I can remove current relationships with categories)
$catGiven = FALSE;
$cats = array();
foreach ($this->importLangs as $lang => $selected) {
if (!$selected)
continue;
$key = $this->_buildFieldKey('categories', 'name', FALSE, $lang, $this->_countSelectedLangs($this->importLangs) > 1);
if (!$this->importFieldCheckedStates[$key])
continue;
$catsHier = explode($this->internalSeparator, $prodArr[$key]);
for ($i = 0; $i < count($catsHier); $i++) {
$catNames = explode($this->internalSeparator2, $catsHier[$i]);
for ($j = 0; $j < count($catNames); $j++) {
$cats[$i][$j][$lang] = $catNames[$j];
$catGiven = TRUE;
}
}
}
if (!$catGiven)
return FALSE;
if ($updating) {
# Removing current relationships with categories. I DO NOT delete categories
$query = "DELETE
FROM `#__jshopping_products_to_categories`
WHERE product_id = $pid";
$this->DB->setQuery($query);
$this->DB->query();
}
for ($i = 0; $i < count($cats); $i++) {
# Parent ID for next category in hierarchy
$parCatId = 0;
for ($j = 0; $j < count($cats[$i]); $j++) {
$fakeProdArr = array();
foreach ($this->importLangs as $lang => $selected) {
if (!$selected)
continue;
$key = $this->_buildFieldKey('categories', 'name', FALSE, $lang, $this->_countSelectedLangs($this->importLangs) > 1);
$fakeProdArr[$key] = $cats[$i][$j][$lang];
}
# Search for category with same name (in all checked langs), maybe we can use existing
$foundCatId = $this->_importSearchForItem('#__jshopping_categories', 'category_id', 'categories', 'name', $fakeProdArr, " AND category_parent_id='$parCatId' ");
if (empty($foundCatId)) {
# No such category found - new record will be created
$catTbl = JTable::getInstance('Category', 'jshop');
$catTbl->category_image = NULL; // Default
$catTbl->category_parent_id = $parCatId;
$catTbl->category_publish = 1; // Default
$catTbl->category_ordertype = 1; // Default
$catTbl->category_template = 'default'; // Default
$catTbl->category_add_date = date(DB_DATE_FORMAT);
$catTbl->products_page = $this->jsConf->count_products_to_page; // Config
$catTbl->products_row = $this->jsConf->count_products_to_row; // Config
# Localized fields
# Function checks if some lang field was checked and no empty, so tbl save has sense
# If no - this subcategory will be just skipped, and parent became next
# This can happens when exist cat name in only one lang, and it field is non-checked for import
if ($this->_importSetLocFields($catTbl, $fakeProdArr, 'categories', 'name', FALSE)){
$this->_importSetLocFields($catTbl, $fakeProdArr, 'categories', 'alias', FALSE);
# Get last order number (for subcategory, not for all categories)
$catTbl->ordering = $this->_importGetNextOrderingNumber(
'#__jshopping_categories', 'ordering', "category_parent_id = $parCatId"
);
$catTbl->store(TRUE);
$parCatId = $catTbl->category_id;
}
} else{
$parCatId = $foundCatId;
}
# I reached the lowest cat in hierarchy, so I can bind it with product
if ($j == count($cats[$i]) - 1) {
# Now $parentId means current cat ID (it will became real parent in next iteration),
# so I use it below
# Make relationship with found category
$query = "INSERT INTO `#__jshopping_products_to_categories`
(product_id, category_id, product_ordering)
VALUES ($pid, $parCatId, " . ($i + 1) . ")";
$this->DB->setQuery($query);
$this->DB->query();
}
}
}