/**
  * 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));
 }
 /**
  * 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;
 }
示例#3
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');
             }
         }
     }
 }
 /**
  * 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;
 }
示例#5
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)
 {
     $search = $manager->createSearch();
     $search->setConditions($search->compare('==', $domain . '.code', array_keys($itemTextMap)));
     $search->setSortations(array($search->sort('+', $domain . '.id')));
     $start = 0;
     $itemIdMap = $itemCodeMap = array();
     do {
         $result = $manager->searchItems($search);
         foreach ($result as $item) {
             $itemIdMap[$item->getId()] = $item->getCode();
             $itemCodeMap[$item->getCode()] = $item->getId();
         }
         $count = count($result);
         $start += $count;
         $search->setSlice($start);
     } while ($count > 0);
     $listManager = $manager->getSubManager('list');
     $search = $listManager->createSearch();
     $expr = array($search->compare('==', $domain . '.list.parentid', array_keys($itemIdMap)), $search->compare('==', $domain . '.list.domain', 'text'));
     $search->setConditions($search->combine('&&', $expr));
     $search->setSortations(array($search->sort('+', $domain . '.list.id')));
     $start = 0;
     do {
         $result = $listManager->searchItems($search);
         foreach ($result as $item) {
             unset($itemTextMap[$itemIdMap[$item->getParentId()]][$item->getRefId()]);
         }
         $count = count($result);
         $start += $count;
         $search->setSlice($start);
     } while ($count > 0);
     $listTypes = $this->_getTextListTypes($manager, $domain);
     foreach ($itemTextMap as $itemCode => $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($itemCodeMap[$itemCode]);
                 $item->setTypeId($listTypes[$listType]->getId());
                 $item->setDomain('text');
                 $item->setRefId($textId);
                 $listManager->saveItem($item);
             } catch (Exception $e) {
                 $this->_getContext()->getLogger()->log('text reference: ' . $e->getMessage(), MW_Logger_Abstract::ERR, 'import');
             }
         }
     }
 }
示例#6
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));
 }