public function ingestAttributeAsociations($items = array()) { $reader = new ArrayReader(); $reader->initialize($items); $this->_engine->callPlugins("general", "importAttributeAssociations", $reader); }
/** * <p>Updates data from a single field taken from the parent record by applying the "innerConfig" (so the contents of the field can be seen as a complete CSV datasource by themselves):</p> * <p>innerConfig is an associative array with the following keys:<ul> * <li>label: human-readable identifier, used for statistics output only</li> * <li>recordSeparator: String used in field content to separate records, e.g. ';'</li> * <li>valueSeparator: String used in field content to separate values from one another (values must be given in order of 'columnNames'</li> * <li>columnNames: array containing columnNames for evaluation of contents</li> * <li>applyDefaultsFromParent: array containing field names for which the default value will be take from the parent record.</li> * <li>applyConditionsFromParent: array containing field names for which there will be a condition with the value from the parent record.</li> * <li>config: config array to be passed on to the inner updateGeneric call. (see updateGeneric documentation)</li> * @param array $parentRecord the parent record's data as an associative array * @param string $fieldContent the string content of the field * @param array $innerConfig the innerConfig (see above) */ private function updateInner(&$parentRecord, $fieldContent, &$innerConfig) { extract($innerConfig); // extract label,recordSeparator,valueSeparator,columnNames,applyDefaultsFromParent,applyConditionsFromParent,config // datasource will be filled with the appropriate values and will later on serve as datasource for the updateGeneric() call $data = array(); // separate field content into substrings for each record and iterate over the results foreach (explode($recordSeparator, $fieldContent) as $entireRecord) { $recorddata = explode($valueSeparator, $entireRecord); $index = 0; $record = array(); foreach ($recorddata as $value) { if (is_numeric($value)) { $value = 0 + $value; } $record[$columnNames[$index]] = $value; $index++; } $data[] = $record; } // prepare ArrayReader out of $givenGroups $datasource = new ArrayReader(); $datasource->initialize($data); $conditions = array(); foreach ($applyConditionsFromParent as $columnName) { $conditions[$columnName] = $parentRecord[$columnName]; } $defaults = array(); foreach ($applyDefaultsFromParent as $columnName) { $defaults[$columnName] = $parentRecord[$columnName]; } // call updateGeneric with prepared data return $this->updateGeneric($datasource, $config, $defaults, $conditions); }
/** * <p>Updates * @param integer $asId attribute_set_id of attribute set to update groups for * @param string $groupString string containing group names and sort orders in format: "<groupname>[:<sortorder>],<groupname>[:<sortorder>],<groupname>[:<sortorder>],..." where <groupname> is a string and <sortorder> an integer, if sortorders are not given, the order number is increased by 1 for each entry * @param string $defaultGroup name of the default group, defaults to "General" */ private function updateAttributeSetGroups($asId, $groupString, $defaultGroup = "General") { $asgTableName = $this->tablename('eav_attribute_group'); // givenGroups will be filled with the appropriate values and will later on serve as datasource for the attribute group updateGeneric() call $givenGroups = array(); $index = 0; // separate groupString into substrings in format "<groupname>:<sortorder>" and iterate over the results foreach (explode(',', $groupString) as $group) { $groupNameAndSortOrder = explode(':', $group, 2); $groupName = trim($groupNameAndSortOrder[0]); // sortorder defaults to $index $sortOrder = $index; // if the group string has a sortorder -> use sortorder from string if (isset($groupNameAndSortOrder[1])) { try { $sortOrder = intval(trim($groupNameAndSortOrder[1])); } catch (Exception $e) { } } $isDefault = $groupName == $defaultGroup; $givenGroups[] = array('attribute_group_name' => $groupName, 'sort_order' => $sortOrder, 'default_id' => $isDefault ? 1 : 0); $index = $sortOrder + 1; } // prepare ArrayReader out of $givenGroups $datasource = new ArrayReader(); $datasource->initialize($givenGroups); // current attribute set id must be set for defaults and fetchConditions we only want to update groups for the current attribute set. $condition = ['attribute_set_id' => $asId]; // call updateGeneric with prepared data return $this->updateGeneric($datasource, $this->ATTRIBUTE_GROUP_ARGS, $condition, $condition); }