/** * Adds plugin data. * * @param MShop_Common_Manager_Interface $pluginManager Plugin manager * @param array $data Associative list of plugin data */ protected function _addPluginData(MShop_Common_Manager_Interface $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 Exception(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 locale language data. * * @param MShop_Common_Manager_Interface $localeManager Locale manager * @param array $data Associative list of locale language data */ protected function _addLocaleLanguageData(MShop_Common_Manager_Interface $localeManager, array $data) { $this->_msg('Adding data for MShop locale languages', 1); $languageItemManager = $localeManager->getSubManager('language', 'Default'); $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'); }
/** * Associates the texts with the products. * * @param MShop_Common_Manager_Interface $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(MShop_Common_Manager_Interface $manager, array $itemTextMap, $domain) { $catalogStart = $catalogTotal = 0; $listManager = $manager->getSubManager('list'); 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.list.parentid', $catalogIds), $criteria->compare('==', 'catalog.list.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 = 'MShop_Common_Item_Type_Interface'; if (!isset($listTypes[$listType]) || $listTypes[$listType] instanceof $iface === false) { throw new 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(), MW_Logger_Abstract::ERR, 'import'); } } } }
/** * Adds the order test data. * * @param MShop_Order_Manager_Interface $orderManager Order Manager * @param array $baseIds List of ids * @param array $testdata Associative list of key/list pairs * @throws MW_Setup_Exception If no type ID is found */ protected function _addOrderData(MShop_Common_Manager_Interface $orderManager, array $baseIds, array $testdata) { $orderStatusManager = $orderManager->getSubManager('status', 'Default'); $ords = array(); $ordItem = $orderManager->createItem(); $this->_conn->begin(); foreach ($testdata['order'] as $key => $dataset) { if (!isset($baseIds[$dataset['baseid']])) { throw new 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 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(); }
/** * Returns a list of list type items. * * @param MShop_Common_Manager_Interface $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 MShop_Common_Item_Type_Interface */ protected function _getTextListTypes(MShop_Common_Manager_Interface $manager, $domain) { if (isset($this->_textListTypes[$domain])) { return $this->_textListTypes[$domain]; } $this->_textListTypes[$domain] = array(); $typeManager = $manager->getSubManager('list')->getSubManager('type'); $search = $typeManager->createSearch(); $search->setConditions($search->compare('==', $domain . '.list.type.domain', 'text')); $search->setSortations(array($search->sort('+', $domain . '.list.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]; }
/** * Gets or creates product list type item with specified code. * * @param MShop_Common_Manager_Interface $productListManager Manager for list types of product domain * @param string $code Code of product list type * * @return int Suggestion product list type id */ protected function _getProductListTypeId(MShop_Common_Manager_Interface $productListManager, $code) { $productListTypeManager = $productListManager->getSubManager('type'); $search = $productListTypeManager->createSearch(); $search->setConditions($search->compare('==', 'product.list.type.code', $code)); $items = $productListTypeManager->searchItems($search); if (($suggestionType = reset($items)) === false) { //create suggestion list type $suggestionType = $productListTypeManager->createItem(); $suggestionType->setCode($code); $suggestionType->setLabel(ucfirst($code)); $suggestionType->setDomain('product'); $suggestionType->setStatus(1); $suggestionType->setSiteId($this->_getContext()->getLocale()->getSiteId()); $productListTypeManager->saveItem($suggestionType); } return $suggestionType->getId(); }