Пример #1
0
 /**
  * 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');
 }
 /**
  * Removes all customer unit test entries
  *
  * @param MShop_Common_Manager_Interface $customerManager Customer manager
  * @param MShop_Common_Manager_Interface $customerAddressManager Customer address manager
  */
 protected function _cleanupCustomerData(MShop_Common_Manager_Interface $customerManager, MShop_Common_Manager_Interface $customerAddressManager)
 {
     $search = $customerManager->createSearch();
     $search->setConditions($search->compare('==', 'customer.website', 'unittest.aimeos.org'));
     $customerItems = $customerManager->searchItems($search);
     $search = $customerAddressManager->createSearch();
     $search->setConditions($search->compare('==', 'customer.address.website', 'unittest.aimeos.org'));
     $addressItems = $customerAddressManager->searchItems($search);
     $customerAddressManager->deleteItems(array_keys($addressItems));
     $customerManager->deleteItems(array_keys($customerItems));
 }
 /**
  * Adds the customer address test data.
  *
  * @param array $testdata Associative list of key/list pairs
  * @param MShop_Common_Manager_Interface $customerAddressManager Customer address manager
  * @param array $parentIds Associative list of keys of the customer test data and customer IDs
  * @throws MW_Setup_Exception If a required ID is not available
  */
 protected function _addCustomerAddressData(array $testdata, MShop_Common_Manager_Interface $customerAddressManager, array $parentIds)
 {
     $address = $customerAddressManager->createItem();
     foreach ($testdata['customer/address'] as $dataset) {
         if (!isset($parentIds[$dataset['refid']])) {
             throw new MW_Setup_Exception(sprintf('No customer ID found for "%1$s"', $dataset['refid']));
         }
         $address->setId(null);
         $address->setCompany($dataset['company']);
         $address->setVatID(isset($dataset['vatid']) ? $dataset['vatid'] : '');
         $address->setSalutation($dataset['salutation']);
         $address->setTitle($dataset['title']);
         $address->setFirstname($dataset['firstname']);
         $address->setLastname($dataset['lastname']);
         $address->setAddress1($dataset['address1']);
         $address->setAddress2($dataset['address2']);
         $address->setAddress3($dataset['address3']);
         $address->setPostal($dataset['postal']);
         $address->setCity($dataset['city']);
         $address->setState($dataset['state']);
         $address->setCountryId($dataset['countryid']);
         $address->setTelephone($dataset['telephone']);
         $address->setEmail($dataset['email']);
         $address->setTelefax($dataset['telefax']);
         $address->setWebsite($dataset['website']);
         $address->setLanguageId($dataset['langid']);
         $address->setFlag($dataset['flag']);
         $address->setPosition($dataset['pos']);
         $address->setRefId($parentIds[$dataset['refid']]);
         $customerAddressManager->saveItem($address, false);
     }
 }
 /**
  * Returns the referenced product IDs from the test data.
  *
  * @param MShop_Common_Manager_Interface $manager Product manager
  * @param string[] keys Unique keys to identify the products
  * @throws MW_Setup_Exception
  */
 private function _getProductRefIds(MShop_Common_Manager_Interface $manager, array $keys)
 {
     $codes = $refIds = array();
     foreach ($keys as $dataset) {
         if (($pos = strpos($dataset, '/')) === false || ($str = substr($dataset, $pos + 1)) == false) {
             throw new MW_Setup_Exception(sprintf('Some keys for ref product are set wrong "%1$s"', $dataset));
         }
         $codes[] = $str;
     }
     $search = $manager->createSearch();
     $search->setConditions($search->compare('==', 'product.code', $codes));
     foreach ($manager->searchItems($search) as $item) {
         $refIds['product/' . $item->getCode()] = $item->getId();
     }
     return $refIds;
 }
Пример #5
0
 /**
  * Adds locale data.
  *
  * @param MShop_Common_Manager_Interface $localeItemManager Locale manager
  * @param array $data Associative list of locale data
  */
 protected function _addLocaleData(MShop_Common_Manager_Interface $localeItemManager, array $data, array $siteIds)
 {
     $this->_msg('Adding data for MShop locales', 1);
     $localeItem = $localeItemManager->createItem();
     foreach ($data as $key => $dataset) {
         if (!isset($siteIds[$dataset['siteid']])) {
             throw new MW_Setup_Exception(sprintf('No ID for site for key "%1$s" found', $dataset['siteid']));
         }
         $localeItem->setId(null);
         $localeItem->setSiteId($siteIds[$dataset['siteid']]);
         $localeItem->setLanguageId($dataset['langid']);
         $localeItem->setCurrencyId($dataset['currencyid']);
         $localeItem->setPosition($dataset['pos']);
         $localeItem->setStatus($dataset['status']);
         try {
             $localeItemManager->saveItem($localeItem);
         } catch (Exception $e) {
         }
         // if locale combination was already available
     }
     $this->_status('done');
 }
Пример #6
0
 /**
  * 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');
             }
         }
     }
 }
Пример #7
0
 /**
  * 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();
 }
 /**
  * Retrieves the product IDs for the used codes
  * 
  * @param MShop_Common_Manager_Interface $productManager Product manager object
  * @return array Associative list of product codes as key (e.g. product/CNC) and IDs as value
  */
 protected function _getProductIds(MShop_Common_Manager_Interface $productManager)
 {
     $entry = array();
     $search = $productManager->createSearch();
     foreach ($productManager->searchItems($search) as $id => $item) {
         $entry['product/' . $item->getCode()] = $id;
     }
     return $entry;
 }
Пример #9
0
 /**
  * Saves a text item from the given data.
  *
  * @param MShop_Common_Manager_Interface $textManager Text manager object
  * @param array $row Row from import file
  * @param array $textTypeMap Associative list of text type IDs as keys and text type codes as values
  * @param array $codeIdMap 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
  * @return array Updated two dimensional associated list of codes and text IDs as key
  */
 private function _saveTextItem(MShop_Common_Manager_Interface $textManager, array $row, array $textTypeMap, array $codeIdMap, $domain)
 {
     $value = isset($row[6]) ? $row[6] : '';
     $textId = isset($row[5]) ? $row[5] : '';
     if ($textId != '' || $value != '') {
         $item = $textManager->createItem();
         if ($textId != '') {
             $item->setId($textId);
         }
         $item->setLanguageId($row[0] != '' ? $row[0] : null);
         $item->setTypeId($textTypeMap[$row[4]]);
         $item->setDomain($domain);
         $item->setLabel(mb_strcut($value, 0, 255));
         $item->setContent($value);
         $item->setStatus(1);
         $textManager->saveItem($item);
         $codeIdMap[$row[2]][$item->getId()] = $row[3];
     }
     return $codeIdMap;
 }
Пример #10
0
 /**
  * Adds the customer group test data.
  *
  * @param array $testdata Associative list of key/list pairs
  * @param MShop_Common_Manager_Interface $customerGroupManager Customer group manager
  * @param array $parentIds Associative list of keys of the customer test data and customer IDs
  * @throws MW_Setup_Exception If a required ID is not available
  */
 protected function _addCustomerGroupData(array $testdata, MShop_Common_Manager_Interface $customerGroupManager, array $parentIds)
 {
     $group = $customerGroupManager->createItem();
     foreach ($testdata['customer/group'] as $dataset) {
         $group->setId(null);
         $group->setCode($dataset['code']);
         $group->setLabel($dataset['label']);
         $customerGroupManager->saveItem($group, false);
     }
 }
Пример #11
0
 /**
  * Optionally first remove all suggested products from product list.
  *
  * @param int $productId Product id
  * @param int $listTypeId Product list type id
  * @param MShop_Common_Manager_Interface $productListManager Manager for list types of product domain
  */
 protected function _removeProductSuggestions($productId, $listTypeId, MShop_Common_Manager_Interface $productListManager)
 {
     $search = $productListManager->createSearch();
     $expr = array($search->compare('==', 'product.list.parentid', $productId), $search->compare('==', 'product.list.type.id', $listTypeId));
     $search->setConditions($search->combine('&&', $expr));
     $listItems = $productListManager->searchItems($search);
     $productListManager->deleteItems(array_keys($listItems));
 }