/** * Adds plugin data. * * @param \Aimeos\MShop\Common\Manager\Iface $pluginManager Plugin manager * @param array $data Associative list of plugin data */ protected function addPluginData(\Aimeos\MShop\Common\Manager\Iface $pluginManager, array $data) { $this->msg('Adding data for MShop plugins', 1); $types = array(); $manager = $pluginManager->getSubManager('type'); foreach ($manager->searchItems($manager->createSearch()) as $item) { $types['plugin/' . $item->getCode()] = $item; } $num = $total = 0; $item = $pluginManager->createItem(); foreach ($data as $key => $dataset) { $total++; if (!isset($types[$dataset['typeid']])) { throw new \RuntimeException(sprintf('No plugin type "%1$s" found', $dataset['typeid'])); } $item->setId(null); $item->setTypeId($types[$dataset['typeid']]->getId()); $item->setProvider($dataset['provider']); $item->setLabel($dataset['label']); $item->setConfig($dataset['config']); $item->setStatus($dataset['status']); if (isset($dataset['position'])) { $item->setPosition($dataset['position']); } try { $pluginManager->saveItem($item); $num++; } catch (\Exception $e) { } // if plugin configuration was already available } $this->status($num > 0 ? $num . '/' . $total : 'OK'); }
/** * Adds the order test data. * * @param \Aimeos\MShop\Order\Manager\Iface $orderManager Order Manager * @param array $baseIds List of ids * @param array $testdata Associative list of key/list pairs * @throws \Aimeos\MW\Setup\Exception If no type ID is found */ protected function addOrderData(\Aimeos\MShop\Common\Manager\Iface $orderManager, array $baseIds, array $testdata) { $orderStatusManager = $orderManager->getSubManager('status', 'Standard'); $ords = array(); $ordItem = $orderManager->createItem(); $this->conn->begin(); foreach ($testdata['order'] as $key => $dataset) { if (!isset($baseIds[$dataset['baseid']])) { throw new \Aimeos\MW\Setup\Exception(sprintf('No base ID found for "%1$s"', $dataset['baseid'])); } $ordItem->setId(null); $ordItem->setBaseId($baseIds[$dataset['baseid']]); $ordItem->setType($dataset['type']); $ordItem->setDateDelivery($dataset['datedelivery']); $ordItem->setDatePayment($dataset['datepayment']); $ordItem->setDeliveryStatus($dataset['statusdelivery']); $ordItem->setPaymentStatus($dataset['statuspayment']); $ordItem->setRelatedId($dataset['relatedid']); $orderManager->saveItem($ordItem); $ords[$key] = $ordItem->getId(); } $ordStat = $orderStatusManager->createItem(); foreach ($testdata['order/status'] as $dataset) { if (!isset($ords[$dataset['parentid']])) { throw new \Aimeos\MW\Setup\Exception(sprintf('No order ID found for "%1$s"', $dataset['parentid'])); } $ordStat->setId(null); $ordStat->setParentId($ords[$dataset['parentid']]); $ordStat->setType($dataset['type']); $ordStat->setValue($dataset['value']); $orderStatusManager->saveItem($ordStat, false); } $this->conn->commit(); }
/** * Associates the texts with the products. * * @param \Aimeos\MShop\Common\Manager\Iface $manager Manager object (attribute, product, etc.) for associating the list items * @param array $itemTextMap Two dimensional associated list of codes and text IDs as key * @param string $domain Name of the domain this text belongs to, e.g. product, catalog, attribute */ protected function importReferences(\Aimeos\MShop\Common\Manager\Iface $manager, array $itemTextMap, $domain) { $catalogStart = $catalogTotal = 0; $listManager = $manager->getSubManager('lists'); do { $criteria = $manager->createSearch(); $criteria->setConditions($criteria->compare('==', 'catalog.id', array_keys($itemTextMap))); $catalogItems = $manager->searchItems($criteria); $catalogStart += count($catalogItems); $catalogIds = array(); foreach ($catalogItems as $item) { $catalogIds[] = $item->getId(); } $listStart = $listTotal = 0; do { $criteria = $listManager->createSearch(); $expr = array($criteria->compare('==', 'catalog.lists.parentid', $catalogIds), $criteria->compare('==', 'catalog.lists.domain', 'text')); $criteria->setConditions($criteria->combine('&&', $expr)); $listItems = $listManager->searchItems($criteria, array(), $listTotal); $listStart += count($catalogItems); foreach ($listItems as $item) { unset($itemTextMap[$item->getParentId()][$item->getRefId()]); } } while ($listStart < $listTotal); } while ($catalogStart < $catalogTotal); $listTypes = $this->getTextListTypes($manager, 'catalog'); foreach ($itemTextMap as $catalogCode => $textIds) { foreach ($textIds as $textId => $listType) { try { $iface = '\\Aimeos\\MShop\\Common\\Item\\Type\\Iface'; if (!isset($listTypes[$listType]) || $listTypes[$listType] instanceof $iface === false) { throw new \Aimeos\Controller\ExtJS\Exception(sprintf('Invalid list type "%1$s"', $listType)); } $item = $listManager->createItem(); $item->setParentId($catalogCode); $item->setTypeId($listTypes[$listType]->getId()); $item->setDomain('text'); $item->setRefId($textId); $listManager->saveItem($item); } catch (\Exception $e) { $this->getContext()->getLogger()->log('catalog text reference: ' . $e->getMessage(), \Aimeos\MW\Logger\Base::ERR, 'import'); } } } }
/** * Adds locale language data. * * @param \Aimeos\MShop\Common\Manager\Iface $localeManager Locale manager * @param array $data Associative list of locale language data */ protected function addLocaleLanguageData(\Aimeos\MShop\Common\Manager\Iface $localeManager, array $data) { $this->msg('Adding data for MShop locale languages', 1); $languageItemManager = $localeManager->getSubManager('language', 'Standard'); $num = $total = 0; foreach ($data as $dataset) { $total++; $languageItem = $languageItemManager->createItem(); $languageItem->setCode($dataset['id']); $languageItem->setLabel($dataset['label']); $languageItem->setStatus($dataset['status']); try { $languageItemManager->saveItem($languageItem); $num++; } catch (\Exception $e) { } // if language was already available } $this->status($num > 0 ? $num . '/' . $total : 'OK'); }
/** * Adds the data from the given object to the item * * @param \Aimeos\MShop\Common\Manager\Iface $manager Manager object * @param \Aimeos\MShop\Common\Item\Iface $item Item object to add the data to * @param \stdClass $data Object with "attributes" property * @param string $domain Domain of the type item * @return \Aimeos\MShop\Common\Item\Iface Item including the data */ protected function addItemData(\Aimeos\MShop\Common\Manager\Iface $manager, \Aimeos\MShop\Common\Item\Iface $item, \stdClass $data, $domain) { if (isset($data->attributes)) { $attr = (array) $data->attributes; $key = str_replace('/', '.', $item->getResourceType()); if (isset($attr[$key . '.type'])) { $typeItem = $manager->getSubManager('type')->findItem($attr[$key . '.type'], array(), $domain); $attr[$key . '.typeid'] = $typeItem->getId(); } $item->fromArray($attr); } return $item; }
/** * Returns a list of list type items. * * @param \Aimeos\MShop\Common\Manager\Iface $manager Manager object (attribute, product, etc.) * @param string $domain Domain the list items must be associated to * @return array Associative list of list type codes and items implementing \Aimeos\MShop\Common\Item\Type\Iface */ protected function getTextListTypes(\Aimeos\MShop\Common\Manager\Iface $manager, $domain) { if (isset($this->textListTypes[$domain])) { return $this->textListTypes[$domain]; } $this->textListTypes[$domain] = array(); $typeManager = $manager->getSubManager('lists')->getSubManager('type'); $search = $typeManager->createSearch(); $search->setConditions($search->compare('==', $domain . '.lists.type.domain', 'text')); $search->setSortations(array($search->sort('+', $domain . '.lists.type.code'))); $start = 0; do { $result = $typeManager->searchItems($search); foreach ($result as $typeItem) { $this->textListTypes[$domain][$typeItem->getCode()] = $typeItem; } $count = count($result); $start += $count; $search->setSlice($start); } while ($count > 0); return $this->textListTypes[$domain]; }