public function updateIndex(OnlineShop_Framework_ProductInterfaces_IIndexable $object) { if (!$this->tenantConfig->isActive($object)) { Logger::info("Tenant {$this->name} is not active."); return; } $subObjectIds = $this->tenantConfig->createSubIdsForObject($object); foreach ($subObjectIds as $subObjectId => $object) { if ($object->getOSDoIndexProduct() && $this->tenantConfig->inIndex($object)) { $a = Pimcore::inAdmin(); $b = \Pimcore\Model\Object\AbstractObject::doGetInheritedValues(); Pimcore::unsetAdminMode(); \Pimcore\Model\Object\AbstractObject::setGetInheritedValues(true); $hidePublishedMemory = \Pimcore\Model\Object\AbstractObject::doHideUnpublished(); \Pimcore\Model\Object\AbstractObject::setHideUnpublished(false); $categories = $object->getCategories(); $themes = $object->getTheme(); $categoryIds = array(); $parentCategoryIds = array(); if ($categories) { foreach ($categories as $c) { $parent = $c; if ($parent != null) { if ($parent->getOSProductsInParentCategoryVisible()) { while ($parent && $parent instanceof OnlineShop_Framework_AbstractCategory) { $parentCategoryIds[$parent->getId()] = $parent->getId(); $parent = $parent->getParent(); } } else { $parentCategoryIds[$parent->getId()] = $parent->getId(); } $categoryIds[$c->getId()] = $c->getId(); } } } $themeIds = array(); if ($themes) { foreach ($themes as $theme) { $parent = $theme; if ($parent != null) { $themeIds[$theme->getId()] = $theme->getId(); } } } ksort($categoryIds); $virtualProductId = $subObjectId; $virtualProductActive = $object->isActive(); if ($object->getOSIndexType() == "variant") { $virtualProductId = $this->tenantConfig->createVirtualParentIdForSubId($object, $subObjectId); } $virtualProduct = \Pimcore\Model\Object\AbstractObject::getById($virtualProductId); if ($virtualProduct && method_exists($virtualProduct, "isActive")) { $virtualProductActive = $virtualProduct->isActive(); } $data = array("o_id" => $subObjectId, "o_classId" => $object->getClassId(), "o_virtualProductId" => $virtualProductId, "o_virtualProductActive" => $virtualProductActive, "o_parentId" => $object->getOSParentId(), "o_type" => $object->getOSIndexType(), "categoryIds" => ',' . implode(",", $categoryIds) . ",", "parentCategoryIds" => ',' . implode(",", $parentCategoryIds) . ",", "priceSystemName" => $object->getPriceSystemName(), "active" => $object->isActive(), "inProductList" => $object->isActive(true), "theme" => ',' . implode(",", $themeIds) . ","); $relationData = array(); $columnConfig = $this->columnConfig->column; if (!empty($columnConfig->name)) { $columnConfig = array($columnConfig); } else { if (empty($columnConfig)) { $columnConfig = array(); } } foreach ($columnConfig as $column) { try { $value = null; if (!empty($column->getter)) { $getter = $column->getter; $value = $getter::get($object, $column->config, $subObjectId, $this->tenantConfig); } else { if (!empty($column->fieldname)) { $getter = "get" . ucfirst($column->fieldname); } else { $getter = "get" . ucfirst($column->name); } if (method_exists($object, $getter)) { $value = $object->{$getter}($column->locale); } } if (!empty($column->interpreter)) { $interpreter = $column->interpreter; $value = $interpreter::interpret($value, $column->config); $interpreterObject = new $interpreter(); if ($interpreterObject instanceof OnlineShop_Framework_IndexService_RelationInterpreter) { foreach ($value as $v) { $relData = array(); $relData['src'] = $subObjectId; $relData['src_virtualProductId'] = $virtualProductId; $relData['dest'] = $v['dest']; $relData['fieldname'] = $column->name; $relData['type'] = $v['type']; $relationData[] = $relData; } } else { $data[$column->name] = $value; } } else { $data[$column->name] = $value; } if (is_array($data[$column->name])) { $data[$column->name] = OnlineShop_Framework_IndexService_Tenant_IWorker::MULTISELECT_DELIMITER . implode($data[$column->name], OnlineShop_Framework_IndexService_Tenant_IWorker::MULTISELECT_DELIMITER) . OnlineShop_Framework_IndexService_Tenant_IWorker::MULTISELECT_DELIMITER; } } catch (Exception $e) { Logger::err("Exception in IndexService: " . $e->getMessage(), $e); } } if ($a) { Pimcore::setAdminMode(); } \Pimcore\Model\Object\AbstractObject::setGetInheritedValues($b); \Pimcore\Model\Object\AbstractObject::setHideUnpublished($hidePublishedMemory); try { $this->doInsertData($data); } catch (Exception $e) { Logger::warn("Error during updating index table: " . $e); } try { $this->db->delete($this->tenantConfig->getRelationTablename(), "src = " . $this->db->quote($subObjectId)); foreach ($relationData as $rd) { $this->db->insert($this->tenantConfig->getRelationTablename(), $rd); } } catch (Exception $e) { Logger::warn("Error during updating index relation table: " . $e->getMessage(), $e); } } else { Logger::info("Don't adding product " . $subObjectId . " to index."); try { $this->db->delete($this->tenantConfig->getTablename(), "o_id = " . $this->db->quote($subObjectId)); } catch (Exception $e) { Logger::warn("Error during updating index table: " . $e->getMessage(), $e); } try { $this->db->delete($this->tenantConfig->getRelationTablename(), "src = " . $this->db->quote($subObjectId)); } catch (Exception $e) { Logger::warn("Error during updating index relation table: " . $e->getMessage(), $e); } try { if ($this->tenantConfig->getTenantRelationTablename()) { $this->db->delete($this->tenantConfig->getTenantRelationTablename(), "o_id = " . $this->db->quote($subObjectId)); } } catch (Exception $e) { Logger::warn("Error during updating index tenant relation table: " . $e->getMessage(), $e); } } $this->tenantConfig->updateSubTenantEntries($object, $subObjectId); } //cleans up all old zombie data $this->doCleanupOldZombieData($object, $subObjectIds); }