/**
  * 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');
 }
 /**
  * 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));
 }
 /**
  * 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;
 }
 /**
  * Returns the customer group type item for the given code
  *
  * @param \Aimeos\MShop\Common\Manager\Iface $listManager Aimeos customer list manager object
  * @param string $code Unique code for a customer list type
  * @return \Aimeos\MShop\Common\Item\Type\Iface Aimeos customer list type item object
  * @throws \Exception If no customer list type item for the given code is found
  */
 protected function getTypeItem(\Aimeos\MShop\Common\Manager\Iface $listManager, $code)
 {
     $manager = $listManager->getSubmanager('type');
     $search = $manager->createSearch();
     $expr = array($search->compare('==', 'customer.lists.type.domain', 'customer/group'), $search->compare('==', 'customer.lists.type.code', $code));
     $search->setConditions($search->combine('&&', $expr));
     $result = $manager->searchItems($search);
     if (($item = reset($result)) === false) {
         $msg = sprintf('No user list type item for domain "%1$s" and code "%2$s" found', 'customer/group', $code);
         throw new \Exception($msg);
     }
     return $item;
 }
 /**
  * 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;
 }
Example #6
0
 /**
  * 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();
 }
Example #7
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);
 }
Example #8
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');
             }
         }
     }
 }
 /**
  * Adds locale data.
  *
  * @param \Aimeos\MShop\Common\Manager\Iface $localeItemManager Locale manager
  * @param array $data Associative list of locale data
  */
 protected function addLocaleData(\Aimeos\MShop\Common\Manager\Iface $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 \Aimeos\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');
 }
Example #10
0
 /**
  * Saves and returns the new or updated item
  *
  * @param \Aimeos\MShop\Common\Manager\Iface $manager Manager responsible for the items
  * @param \stdClass $entry Object including "id" and "attributes" elements
  * @return \Aimeos\MShop\Common\Item\Iface New or updated item
  */
 protected function saveEntry(\Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $entry)
 {
     $targetId = isset($entry->targetid) ? $entry->targetid : null;
     $refId = isset($entry->refid) ? $entry->refid : null;
     if (isset($entry->id)) {
         $item = $manager->getItem($entry->id);
         $item = $this->addItemData($manager, $item, $entry, $item->getResourceType());
         $manager->saveItem($item);
         if (isset($entry->parentid) && $targetId !== null) {
             $manager->moveItem($item->getId(), $entry->parentid, $targetId, $refId);
         }
     } else {
         $item = $manager->createItem();
         $item = $this->addItemData($manager, $item, $entry, $item->getResourceType());
         $manager->insertItem($item, $targetId, $refId);
     }
     if (isset($entry->relationships)) {
         $this->saveRelationships($manager, $item, $entry->relationships);
     }
     return $manager->getItem($item->getId());
 }
Example #11
0
 /**
  * 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;
 }
Example #12
0
 /**
  * Saves a text item from the given data.
  *
  * @param \Aimeos\MShop\Common\Manager\Iface $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(\Aimeos\MShop\Common\Manager\Iface $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;
 }
Example #13
0
 /**
  * Adds the customer group test data.
  *
  * @param array $testdata Associative list of key/list pairs
  * @param \Aimeos\MShop\Common\Manager\Iface $customerGroupManager Customer group manager
  * @throws \Aimeos\MW\Setup\Exception If a required ID is not available
  */
 protected function addCustomerGroupData(array $testdata, \Aimeos\MShop\Common\Manager\Iface $customerGroupManager)
 {
     $group = $customerGroupManager->createItem();
     foreach ($testdata['customer/group'] as $dataset) {
         $group->setId(null);
         $group->setCode($dataset['code']);
         $group->setLabel($dataset['label']);
         try {
             $customerGroupManager->saveItem($group, false);
         } catch (\Exception $e) {
         }
         // ignore duplicates
     }
 }
Example #14
0
 /**
  * Adds the customer group test data.
  *
  * @param array $testdata Associative list of key/list pairs
  * @param \Aimeos\MShop\Common\Manager\Iface $customerGroupManager Customer group manager
  * @param array $parentIds Associative list of keys of the customer test data and customer IDs
  * @throws \Aimeos\MW\Setup\Exception If a required ID is not available
  */
 protected function addCustomerGroupData(array $testdata, \Aimeos\MShop\Common\Manager\Iface $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);
     }
 }
Example #15
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;
 }