/**
  * Removes all customer unit test entries
  *
  * @param \Aimeos\MShop\Common\Manager\Iface $customerManager Customer manager
  * @param \Aimeos\MShop\Common\Manager\Iface $customerAddressManager Customer address manager
  */
 protected function cleanupCustomerData(\Aimeos\MShop\Common\Manager\Iface $customerManager, \Aimeos\MShop\Common\Manager\Iface $customerAddressManager)
 {
     $search = $customerManager->createSearch();
     $search->setConditions($search->compare('=~', 'customer.code', 'unitCustomer'));
     $customerItems = $customerManager->searchItems($search);
     $search = $customerAddressManager->createSearch();
     $search->setConditions($search->compare('=~', 'customer.address.email', 'unitCustomer'));
     $addressItems = $customerAddressManager->searchItems($search);
     $customerAddressManager->deleteItems(array_keys($addressItems));
     $customerManager->deleteItems(array_keys($customerItems));
 }
Ejemplo n.º 2
0
 /**
  * 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)
 {
     $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('lists');
     $search = $listManager->createSearch();
     $expr = array($search->compare('==', $domain . '.lists.parentid', array_keys($itemIdMap)), $search->compare('==', $domain . '.lists.domain', 'text'));
     $search->setConditions($search->combine('&&', $expr));
     $search->setSortations(array($search->sort('+', $domain . '.lists.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 = '\\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($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(), \Aimeos\MW\Logger\Base::ERR, 'import');
             }
         }
     }
 }
 /**
  * Retrieves the product IDs for the used codes
  * 
  * @param \Aimeos\MShop\Common\Manager\Iface $productManager Product manager object
  * @return array Associative list of product codes as key (e.g. product/CNC) and IDs as value
  */
 protected function getProductIds(\Aimeos\MShop\Common\Manager\Iface $productManager)
 {
     $entry = array();
     $search = $productManager->createSearch();
     foreach ($productManager->searchItems($search) as $id => $item) {
         $entry['product/' . $item->getCode()] = $id;
     }
     return $entry;
 }
Ejemplo n.º 4
0
 /**
  * Returns the referenced product IDs from the test data.
  *
  * @param \Aimeos\MShop\Common\Manager\Iface $manager Product manager
  * @param string[] keys Unique keys to identify the products
  * @throws \Aimeos\MW\Setup\Exception
  */
 private function getProductRefIds(\Aimeos\MShop\Common\Manager\Iface $manager, array $keys)
 {
     $codes = $refIds = array();
     foreach ($keys as $dataset) {
         if (($pos = strpos($dataset, '/')) === false || ($str = substr($dataset, $pos + 1)) === false) {
             throw new \Aimeos\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;
 }
Ejemplo n.º 5
0
 /**
  * Returns the domain items for the given IDs including the referenced items
  *
  * @param \Aimeos\MShop\Common\Manager\Iface $manager Domain specific manager
  * @param string $key Domain key for seaching the items by ID
  * @param string[] $ids Unique domain IDs
  * @param string[] List of domain names whose items should be fetched too
  * @return \Aimeos\MShop\Common\Item\Iface[] Domain items
  */
 protected function getDomainItems(\Aimeos\MShop\Common\Manager\Iface $manager, $key, array $ids, array $domains)
 {
     $search = $manager->createSearch(true);
     $expr = array($search->compare('==', $key, $ids), $search->getConditions());
     $search->setConditions($search->combine('&&', $expr));
     return $manager->searchItems($search, $domains);
 }
Ejemplo n.º 6
0
 /**
  * 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');
             }
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * Returns the list items associated to the given user ID
  *
  * @param \Aimeos\MShop\Common\Manager\Iface $manager Customer list manager
  * @param array $refIds IDs of the referenced items
  * @param string $typeId List type ID of the referenced items
  * @param string $userId Unique user ID
  * @return array Associative list of the reference IDs as keys and the list items as values
  */
 protected function getListItems(\Aimeos\MShop\Common\Manager\Iface $manager, array $refIds, $typeId, $userId)
 {
     $search = $manager->createSearch();
     $expr = array($search->compare('==', 'customer.lists.parentid', $userId), $search->compare('==', 'customer.lists.refid', $refIds), $search->compare('==', 'customer.lists.domain', 'product'), $search->compare('==', 'customer.lists.typeid', $typeId));
     $search->setConditions($search->combine('&&', $expr));
     $items = array();
     foreach ($manager->searchItems($search) as $item) {
         $items[$item->getRefId()] = $item;
     }
     return $items;
 }