Create a new instance from a Buyable.

@param \JohannesSchobel\ShoppingCart\Contracts\Buyable $item
@param array   $options

@return \JohannesSchobel\ShoppingCart\Models\CartItem
346422
public static function fromBuyable(Buyable $item, array $options = [])
    {
        $cartItem = new self(
                         $item->getBuyableIdentifier($options),
                         $item->getBuyableDescription($options),
                         $item->getBuyableType($options),
                         $item->getBuyablePrice($options),
                         $item->getBuyableURI($options),
                         $options
        );

        $cartItem->setModel($item);

        return $cartItem;
    }
1199085
public function setItem(Item $item)
    {
        if ($this->item !== $item) {
            $this->item = $item->addGenre($this);
        }

        return $this;
    }
222232
public static function create(Item $item){
        $returnValue = new Summation($item);
        foreach($item->getInteractions() as $interaction){
            $irp = InteractionResponseProcessing::create(
                            None::CLASS_ID
                            , $interaction->getResponse()
                            , $item
            );
            $returnValue->add($irp, $item);
        }

        return $returnValue;
    }
1170428
public function add(PriorityQueueItem $item) {
        $priority = $item->getPriority();
        if (!isset($this->items[$priority])) {
            $this->items[$priority] = array($item);
        } else {
            $this->items[$priority][] = $item;
        }
        return $this;
    }
1128284
public function subItem($item = [], $options = [])
    {
        $html = '<li>';
        $html .= $this->Html->link($item['title'], $item['url']);
        $html .= '</li>';

        return $html;
    }
255329
public function createResourceViewData(array $options, $item)
    {
        if ($item->getType() === Setting::SETTING_TYPE_TEXT) {
            return $item->getValue();
        }

        if ($item->getType() === Setting::SETTING_TYPE_BOOLEAN) {
            $booleanWidget = $this->container->get('enhavo_app.table.boolean');
            $options['property'] = 'value';
            return $booleanWidget->createResourceViewData($options, $item);
        }

        if ($item->getType() === Setting::SETTING_TYPE_FILE) {
            $pictureWidget = $this->container->get('enhavo_media.table.picture_widget');
            $options['property'] = 'file';
            return $pictureWidget->createResourceViewData($options, $item);
        }

        if ($item->getType() === Setting::SETTING_TYPE_FILES) {
            $pictureWidget = $this->container->get('enhavo_media.table.picture_widget');
            $options['property'] = 'files';
            return $pictureWidget->createResourceViewData($options, $item);
        }

        if ($item->getType() === Setting::SETTING_TYPE_WYSIWYG) {
            return $item->getValue();
        }

        if ($item->getType() === Setting::SETTING_TYPE_DATE) {
            $date = $item->getDate();
            if($date instanceof \DateTime) {
                return $date->format('d.m.y');
            }
            return '';
        }

        if ($item->getType() === Setting::SETTING_TYPE_DATETIME) {
            $date = $item->getDate();
            if($date instanceof \DateTime) {
                return $date->format('d.m.y H:i');
            }
            return '';
        }
        
        return '';
    }
1273024
private function buildItem(array $data, array $options = [])
    {
        $options = array_merge($options, [
            'label' => $data['title'],
        ]);
        if (!empty($data['attributes'])) {
            $options['attributes'] = $data['attributes'];
        }

        // Fix routing / url / path
        if (0 < strlen($data['path'])) {
            $options['uri'] = $data['path'];
        } elseif (0 < strlen($data['route'])) {
            $options['route'] = $data['route'];
            if (!empty($data['parameters'])) {
                $options['routeParameters'] = $data['parameters'];
            }
        }

        $item = $this
            ->factory
            ->createItem($data['name'], $options)
            ->setExtra('translation_domain', false);

        // Children items
        foreach ($this->menus as $menu) {
            if ($data['id'] === intval($menu['parent'])) {
                $item->addChild($this->buildItem($menu));
            }
        }

        // Custom menu event
        if (isset($data['options']['event']) && 0 < strlen($event = $data['options']['event'])) {
            $this->dispatcher->dispatch($event, new MenuEvent($this->factory, $item));
        }

        return $item;
    }
19229
private function parseOption(array $item) : Option
    {
        $name = $item['option'];

        $characteristic = $item['characteristic'] ?? null;

        if (isset($characteristic))
        {
            $characteristic = self::optionCharacteristic($characteristic);
        }

        $type = $item['type'] ?? null;

        $default = $item['default'] ?? null;

        $description = $item['description'] ?? null;

        $fixedName = $item['name'] ?? null;

        $option = new Option($name, $characteristic, $type, $default);

        if (isset($description))
        {
            $option->setDescription($description);
        }

        if (isset($fixedName))
        {
            if ($fixedName[0] === '-')
            {
                throw new OptionLoaderException(
                    "An option's fixed name may not start with a `-`.",
                    $item
                );
            }

            $option->setFixedName($fixedName);
        }

        if (isset($item['aliases']))
        {
            foreach ($item['aliases'] as $alias)
            {
                $aliasCharacteristic = $alias['characteristic'] ?? null;

                if (isset($aliasCharacteristic))
                {
                    $aliasCharacteristic = self::optionCharacteristic(
                        $aliasCharacteristic
                    );
                }

                $aliasName = $alias['option'] ?? null;

                if ( ! isset($aliasName))
                {
                    throw new OptionLoaderException(
                        "An alias must contain its own option name.",
                        $alias
                    );
                }

                new AliasOption($aliasName, $aliasCharacteristic, $option);
            }
        }

        if (isset($fixedName))
        {
            $this->optionCatalogue[$fixedName] = $option;
        }

        $this->optionCatalogue[$option->getPrintableName()] = $option;

        return $option;
    }
362864
protected function prepareEntityItem(array &$item, array $options)
    {
        $this->setItemEntityUrl($item, $options);
        $this->setItemThumb($item, $this->image, $options);

        if ($options['entity'] === 'product') {
            $this->prepareProductItem($item, $options);
        } else {
            $this->setItemIndentation($item);
            $this->setItemUrlActive($item);
            $this->setItemRendered($item, array('item' => $item), $options);
        }
    }
1077017
public function createMainMenu(array $options): ItemInterface
    {
        $menu = $this->factory->createItem('root');

        $event = new MainMenuCollectionEvent($menu);
        $this->dispatcher->dispatch(MainMenuCollectionEvent::NAME, $event);

        return $menu;
    }
283148
private function processRule(Item $item, $ruleName, $options)
    {
        if ($item->stopRules()) {
            return;
        }

        $ruleName = '\NickStuer\EasyValidator\Rules\\' . $ruleName;

        if (!class_exists($ruleName)) {
            throw new RuleNotFoundException;
        }

        /**
         * @var \NickStuer\EasyValidator\RuleInterface $rule
         */
        $rule = new $ruleName;
        if (!$rule->validate($item->getItemValue(), $options)) {
            $this->setValidationStatus(false);
            $item->setValidationStatus(false);

            $message = $rule->getMessage();
            $message = str_replace('{label}', $item->getItemLabel(), $message);
            $message = str_replace('{option1}', $options, $message);
            $item->setMessage($message);
        }

        $item->incrementRuleCount();
    }
390820
protected function addItem($alias, $item = null, array $options = null)
    {
        $this->checkIfProtected($alias);

        // Are we adding multiple items?
        if (is_array($alias)) {
            foreach ($alias as $key => $value) {
                $this->addItem($key, $value);
            }
            return $this;
        }

        // No, we are adding a single item
        $repo = $this->getItemsName();
        $loc = &$this->$repo;

        $pieces = explode('.', $alias);
        $currentLevel = 1;
        $nestLevels = count($pieces) - 1;

        foreach ($pieces as $step) {
            // Make sure we are not trying to nest under a non-array. This is gross
            // https://github.com/chrismichaels84/data-manager/issues/6

            // 1. Not at the last level (the one with the desired value),
            // 2. The nest level is already set,
            // 3. and is not an array
            if ($nestLevels > $currentLevel && isset($loc[$step]) && !is_array($loc[$step])) {
                throw new NestingUnderNonArrayException();
            }

            $loc = &$loc[$step];
            $currentLevel++;
        }
        $loc = $item;

        return $this;
    }
969098
protected function convertItem($item)
    {
        foreach ($item as $key => $value) {
            if (!isset($this->converters[$key])) {
                continue;
            }

            foreach ($this->converters[$key] as $converter) {
                $item[$key] = call_user_func($converter, $item[$key]);
            }
        }

        return $item;
    }
1267682
protected function fromArray( \Aimeos\MShop\Product\Item\Iface $item, array $data )
	{
		$listManager = \Aimeos\MShop::create( $this->getContext(), 'product/lists' );

		$listItem = $listManager->createItem()->setType( 'bought-together' );
		$listItems = $item->getListItems( 'product', 'bought-together', null, false );

		foreach( $this->getValue( $data, 'product.lists.id', [] ) as $idx => $id )
		{
			if( isset( $listItems[$id] ) ) {
				$litem = $listItems[$id]; unset( $listItems[$id] );
			} else {
				$litem = clone $listItem;
			}

			$litem->setId( $id );
			$litem->setPosition( $idx );
			$litem->setRefId( $this->getValue( $data, 'product.lists.refid/' . $idx ) );

			$item->addListItem( 'product', $litem, $litem->getRefItem() );
		}

		return $item->deleteListItems( $listItems );
	}
1334671
public function createAdminMenu(array $options): ItemInterface
    {
        $menu = $this->factory->createItem('root');

        $event = new AdminMenuCollectionEvent($menu);
        $this->dispatcher->dispatch(AdminMenuCollectionEvent::NAME, $event);

        return $menu;
    }
335075
public function addItem(PricedItemInterface $item)
    {
        if ($this->hasItem($item)) {
            return $this;
        }

        foreach ($this->items as $existingItem) {
            if ($item->equals($existingItem)) {
                $existingItem->merge($item, false);

                $this->itemsTotal = null;
                $this->total = null;

                return $this;
            }
        }

        $item->setContainer($this);
        $this->items->add($item);

        $this->itemsTotal = null;
        $this->total = null;

        return $this;
    }
1250021
protected function fromArray( \Aimeos\MShop\Product\Item\Iface $item, array $data )
	{
		$manager = \Aimeos\MShop::create( $this->getContext(), 'product/property' );
		$typeManager = \Aimeos\MShop::create( $this->getContext(), 'product/property/type' );

		foreach( $data as $type => $value )
		{
			$propItems = $item->getPropertyItems( $type, false );

			if( ( $value = trim( $value ) ) != '' )
			{
				if( ( $propItem = reset( $propItems ) ) === false ) {
					$propItem = $manager->createItem()->setType( $type );
				}

				$propItem->setLanguageId( null );
				$propItem->setValue( $value );

				$item->addPropertyItem( $propItem );
			}
			else
			{
				$item->deletePropertyItems( $propItems );
			}
		}
	}