Beispiel #1
0
 /**
  * Updates the list items to the referenced items for the given domain and type
  *
  * @param \Aimeos\MShop\Common\Item\ListRef\Iface $item Item including references to other domain items
  * @param array $map Associative list of reference ID as key and list of list item properties as key/value pairs
  * @param string $domain Domain name of the referenced items
  * @param string $type List type for the referenced items
  */
 public function updateListItems(\Aimeos\MShop\Common\Item\ListRef\Iface $item, array $map, $domain, $type)
 {
     $listManager = $this->getSubManager('lists');
     if (!isset($this->typeIds[$domain][$type])) {
         $typeManager = $listManager->getSubManager('type');
         $this->typeIds[$domain][$type] = $typeManager->findItem($type, array(), $domain)->getId();
     }
     $listItem = $listManager->createItem();
     $listItem->setTypeId($this->typeIds[$domain][$type]);
     $listItem->setParentId($item->getId());
     $listItem->setDomain($domain);
     $listItem->setStatus(1);
     $pos = 0;
     $listRef = $ids = array();
     $listItems = $item->getListItems($domain, $type);
     foreach ($listItems as $id => $listItem) {
         $listRef[$listItem->getRefId()] = $id;
     }
     foreach ($map as $id => $values) {
         $copy = $listItem;
         if (!isset($listRef[$id])) {
             $copy->setId(null);
             $copy->setRefId($id);
         } else {
             $copy = $listItems[$listRef[$id]];
             $ids[] = $listRef[$id];
         }
         $copy->fromArray($values);
         $copy->setPosition($pos++);
         $listManager->saveItem($copy);
     }
     $listManager->deleteItems(array_diff($listRef, $ids));
 }
Beispiel #2
0
 /**
  * Saves the text items referenced indirectly by products
  *
  * @param \Aimeos\MW\DB\Statement\Iface $stmt Prepared SQL statement with place holders
  * @param \Aimeos\MShop\Common\Item\ListRef\Iface $item Item containing associated text items
  * @param array $listTypes Associative list of item ID / list type code pairs
  * @throws \Aimeos\MShop\Index\Exception If no list type for the item is available
  */
 protected function savePrices(\Aimeos\MW\DB\Statement\Iface $stmt, \Aimeos\MShop\Common\Item\ListRef\Iface $item, array $listTypes)
 {
     $context = $this->getContext();
     $siteid = $context->getLocale()->getSiteId();
     $editor = $context->getEditor();
     $date = date('Y-m-d H:i:s');
     foreach ($item->getRefItems('price') as $refId => $refItem) {
         if (!isset($listTypes[$refId])) {
             $msg = sprintf('List type for price item with ID "%1$s" not available', $refId);
             throw new \Aimeos\MShop\Index\Exception($msg);
         }
         foreach ($listTypes[$refId] as $listType) {
             $stmt->bind(1, $item->getId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT);
             $stmt->bind(2, $siteid, \Aimeos\MW\DB\Statement\Base::PARAM_INT);
             $stmt->bind(3, $refId, \Aimeos\MW\DB\Statement\Base::PARAM_INT);
             $stmt->bind(4, $refItem->getCurrencyId());
             $stmt->bind(5, $listType);
             $stmt->bind(6, $refItem->getType());
             $stmt->bind(7, $refItem->getValue());
             $stmt->bind(8, $refItem->getCosts());
             $stmt->bind(9, $refItem->getRebate());
             $stmt->bind(10, $refItem->getTaxRate());
             $stmt->bind(11, $refItem->getQuantity(), \Aimeos\MW\DB\Statement\Base::PARAM_INT);
             $stmt->bind(12, $date);
             //mtime
             $stmt->bind(13, $editor);
             $stmt->bind(14, $date);
             //ctime
             try {
                 $stmt->execute()->finish();
             } catch (\Aimeos\MW\DB\Exception $e) {
             }
             // Ignore duplicates
         }
     }
 }
Beispiel #3
0
 /**
  * Saves the text items referenced indirectly by products
  *
  * @param \Aimeos\MW\DB\Statement\Iface $stmt Prepared SQL statement with place holders
  * @param \Aimeos\MShop\Common\Item\ListRef\Iface $item Item containing associated text items
  * @param array $listTypes Associative list of item ID / list type code pairs
  * @param array $prodIds Associative list of item ID / list of product IDs pairs
  * @throws \Aimeos\MShop\Index\Exception If no list type for the item is available
  */
 protected function saveTexts(\Aimeos\MW\DB\Statement\Iface $stmt, \Aimeos\MShop\Common\Item\ListRef\Iface $item, array $listTypes, array $prodIds)
 {
     $context = $this->getContext();
     $siteid = $context->getLocale()->getSiteId();
     $editor = $context->getEditor();
     $date = date('Y-m-d H:i:s');
     foreach ($item->getRefItems('text') as $refId => $refItem) {
         if ($refItem->getContent() === '') {
             continue;
         }
         if (!isset($listTypes[$refId])) {
             $msg = sprintf('List type for text item with ID "%1$s" not available', $refId);
             throw new \Aimeos\MShop\Index\Exception($msg);
         }
         foreach ($listTypes[$refId] as $listType) {
             foreach ($prodIds[$item->getId()] as $productId) {
                 $this->saveText($stmt, $productId, $siteid, $refId, $refItem->getLanguageId(), $listType, $refItem->getType(), $item->getResourceType(), $refItem->getContent(), $date, $editor);
             }
         }
     }
 }
Beispiel #4
0
 /**
  * Adds expire date and tags for referenced items
  *
  * @param \Aimeos\MShop\Common\Item\ListRef\Iface $item Item with associated list items
  * @param array &$expires Will contain the list of expiration dates
  * @param array &$tags List of tags the new tags will be added to
  * @param boolean $tagAll True of tags for all items should be added, false if only for the main item
  */
 private function addMetaItemRef(\Aimeos\MShop\Common\Item\ListRef\Iface $item, array &$expires, array &$tags, $tagAll)
 {
     foreach ($item->getListItems() as $listitem) {
         if ($tagAll === true) {
             $tags[] = str_replace('/', '_', $listitem->getDomain()) . '-' . $listitem->getRefId();
         }
         if (($date = $listitem->getDateEnd()) !== null) {
             $expires[] = $date;
         }
     }
 }