Exemple #1
0
 /**
  * Delete associations if they exist in magento but not in given data
  *
  * @param array $data
  *
  * @return array
  */
 protected function _pruneAttributesFromAttributeSets(array $data)
 {
     $entityTypeId = $this->_catalogProductEntityTypeId;
     $query = $this->_setup->getConnection()->select()->from($this->_setup->getTable('eav/entity_attribute'))->where('entity_type_id = :entity_type_id');
     $bind = array('entity_type_id' => $this->_catalogProductEntityTypeId);
     $givenAssociations = array();
     foreach ($data as $attribute) {
         $setId = $this->_setup->getAttributeSetId($entityTypeId, $attribute['attribute_set_id']);
         $givenAssociations[] = array('attribute_id' => $this->_setup->getAttributeId($entityTypeId, $attribute['attribute_id']), 'attribute_set_id' => $setId, 'attribute_group_id' => $this->_setup->getAttributeGroupId($entityTypeId, $setId, $attribute['attribute_group_id']));
     }
     $deletedRows = array();
     foreach ($this->_setup->getConnection()->fetchAssoc($query, $bind) as $magAssociation) {
         $rowFound = false;
         while ((list($key, $association) = each($givenAssociations)) && $rowFound === false) {
             if ($association['attribute_id'] === $magAssociation['attribute_id'] && $association['attribute_set_id'] === $magAssociation['attribute_set_id'] && $association['attribute_group_id'] === $magAssociation['attribute_group_id']) {
                 $rowFound = true;
             }
         }
         reset($givenAssociations);
         if (!$rowFound) {
             $deletedRows[$magAssociation['entity_attribute_id']] = $this->_setup->getConnection()->delete($this->_setup->getTable('eav/entity_attribute'), new Zend_Db_Expr('entity_attribute_id = ' . $magAssociation['entity_attribute_id']));
         }
     }
     return $deletedRows;
 }