public function clearIndexEntry(CategoryInterface $category, AttributeValueInterface $value, $subject)
 {
     if ($this->isValid($category)) {
         $attributeIndexer = $value->getAttributeKey()->getSearchIndexer();
         $attributeIndexer->clearIndexEntry($category, $value, $subject);
     }
 }
 /**
  * @param StandardSearchIndexerInterface $category
  * @param Value $value
  * @param mixed $subject
  */
 public function indexEntry(CategoryInterface $category, AttributeValueInterface $value, $subject)
 {
     $columns = $this->connection->getSchemaManager()->listTableColumns($category->getIndexedSearchTable());
     $attributeValue = $value->getSearchIndexValue();
     $details = $category->getSearchIndexFieldDefinition();
     $primary = $details['primary'][0];
     $primaryValue = $category->getIndexedSearchPrimaryKeyValue($subject);
     $columnValues = array();
     /**
      * @var $exists Statement
      */
     $exists = $this->connection->query("select count({$primary}) from {$category->getIndexedSearchTable()} where {$primary} = {$primaryValue}")->fetchColumn();
     if (is_array($attributeValue)) {
         foreach ($attributeValue as $valueKey => $valueValue) {
             $col = $this->getIndexEntryColumn($value->getAttributeKey(), $valueKey);
             if (isset($columns[strtolower($col)])) {
                 $columnValues[$col] = $valueValue;
             }
         }
     } else {
         $col = $this->getIndexEntryColumn($value->getAttributeKey());
         if (isset($columns[strtolower($col)])) {
             $columnValues[$col] = $attributeValue;
         }
     }
     if (count($columnValues)) {
         $primaries = array($primary => $primaryValue);
         if ($exists) {
             $this->connection->update($category->getIndexedSearchTable(), $columnValues, $primaries);
         } else {
             $this->connection->insert($category->getIndexedSearchTable(), $primaries + $columnValues);
         }
     }
 }
Ejemplo n.º 3
0
 public function deleteValue(AttributeValueInterface $attributeValue)
 {
     // Handle legacy attributes with these three lines.
     $controller = $attributeValue->getAttributeKey()->getController();
     $controller->setAttributeValue($attributeValue);
     $controller->deleteValue();
     $genericValue = $attributeValue->getGenericValue();
     if (is_object($genericValue)) {
         $genericValues = $this->getAttributeValueRepository()->findBy(['generic_value' => $genericValue]);
         if (count($genericValues) == 1) {
             $value = $attributeValue->getValueObject();
             if (is_object($value)) {
                 $this->entityManager->remove($value);
                 $this->entityManager->flush();
             }
             $this->entityManager->remove($genericValue);
         }
         $this->entityManager->remove($attributeValue);
     }
     $this->entityManager->flush();
 }