Exemple #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));
 }
Exemple #2
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;
         }
     }
 }