You are here

interface BundleItemInterface in Commerce Product Bundle 8

Provides an interface for defining product bundle item entities.

Hierarchy

Expanded class hierarchy of BundleItemInterface

All classes that implement BundleItemInterface

2 files declare their use of BundleItemInterface
MinQtyLessThanOrEqualMaxQtyConstraintValidatorTest.php in tests/src/Unit/Plugin/Validation/Constraint/MinQtyLessThanOrEqualMaxQtyConstraintValidatorTest.php
ProductBundleItemsWidget.php in src/Plugin/Field/FieldWidget/ProductBundleItemsWidget.php

File

src/Entity/BundleItemInterface.php, line 16

Namespace

Drupal\commerce_product_bundle\Entity
View source
interface BundleItemInterface extends EntityChangedInterface, EntityOwnerInterface {

  /**
   * Gets the product bundle item title.
   *
   * @return string
   *   Title of the product bundle item.
   */
  public function getTitle();

  /**
   * Sets the product bundle item title.
   *
   * @param string $title
   *   The product bundle item title.
   *
   * @return \Drupal\commerce_product_bundle\Entity\BundleItemInterface
   *   The called product bundle item entity.
   */
  public function setTitle($title);

  /**
   * Set whether the product bundle item is required or not.
   *
   * @param bool $required
   *   Set TRUE if required, FALSE if optional.
   *
   * @return \Drupal\commerce_product_bundle\Entity\BundleItemInterface
   *   The called product bundle item entity.
   */
  public function setRequired($required);

  /**
   * Whether the product bundle item is required or not.
   *
   * @return bool
   *   TRUE if required, FALSE if optional.
   */
  public function isRequired();

  /**
   * Gets the product bundle item creation timestamp.
   *
   * @return int
   *   Creation timestamp of the product bundle item.
   */
  public function getCreatedTime();

  /**
   * Sets the product bundle item creation timestamp.
   *
   * @param int $timestamp
   *   The product bundle item creation timestamp.
   *
   * @return \Drupal\commerce_product_bundle\Entity\BundleItemInterface
   *   The called product bundle item entity.
   */
  public function setCreatedTime($timestamp);

  /**
   * Gets the parent bundle entity.
   *
   * @return \Drupal\commerce_product_bundle\Entity\BundleInterface
   *   The product bundle entity, or null.
   */
  public function getBundle();

  /**
   * Gets the parent product bundle ID.
   *
   * @return int
   *   The product bundle ID, or null.
   */
  public function getBundleId();

  /**
   * Gets the bundle item quantity.
   *
   * @return float
   *   The bundle item quantity
   */
  public function getQuantity();

  /**
   * Sets the quantity for the bundle item.
   *
   * @param float $quantity
   *   The bundle item quantity.
   *
   * @return \Drupal\commerce_product_bundle\Entity\BundleItemInterface
   *   The called product bundle item entity.
   */
  public function setQuantity($quantity);

  /**
   * Sets the minimum quantity of the product variations.
   *
   * @param float $minimum_quantity
   *   The minimum quantity.
   *
   * @return \Drupal\commerce_product_bundle\Entity\BundleItemInterface
   *   The called product bundle item entity.
   */
  public function setMinimumQuantity($minimum_quantity);

  /**
   * Gets the minimum quantity of the product variations.
   *
   * @return float
   *   The minimum quantity.
   */
  public function getMinimumQuantity();

  /**
   * Sets the maximum quantity of the product variations.
   *
   * @param float $maximum_quantity
   *   The maximum quantity.
   *
   * @return \Drupal\commerce_product_bundle\Entity\BundleItemInterface
   *   The called product bundle item entity.
   */
  public function setMaximumQuantity($maximum_quantity);

  /**
   * Gets the maximum quantity of the product variations.
   *
   * @return float
   *   The maximum quantity.
   */
  public function getMaximumQuantity();

  /**
   * Gets whether the bundle item has a product set or not.
   *
   * @return bool
   *   TRUE if the bundle item contains a product reference. FALSE otherwise.
   */
  public function hasProduct();

  /**
   * Get the referenced product.
   *
   * @return null|\Drupal\commerce_product\Entity\ProductInterface
   *   The referenced commerce product or null
   *    if no product is referenced.
   */
  public function getProduct();

  /**
   * Gets the bundle item's product id.
   *
   * @return string|int
   *   The bundle item's product id.
   */
  public function getProductId();

  /**
   * Set the referenced product.
   *
   * If a new product is referenced, the variations references will be
   * resetted.
   *
   * @param \Drupal\commerce_product\Entity\ProductInterface $product
   *   The product.
   *
   * @return $this
   */
  public function setProduct(ProductInterface $product);

  /**
   * Sets the variations.
   *
   * If the bundle item doesn't hold a product reference yet, the product of the
   * first variation will be set as the bundle items product.
   *
   * @param \Drupal\commerce_product\Entity\ProductVariationInterface[] $variations
   *   The variations.
   *
   * @throws \InvalidArgumentException
   *    In case the variations don't belong to the same product or if applicable to
   *    the already referenced product.
   *
   * @return \Drupal\commerce_product_bundle\Entity\BundleItemInterface
   *   The called product bundle item entity.
   */
  public function setVariations(array $variations);

  /**
   * Gets whether the bundle item has restricted variations.
   *
   * @return bool
   *   TRUE if the bundle item has restricted available variations, FALSE otherwise.
   */
  public function hasVariations();

  /**
   * Gets the product variations limited by the bundle item or enabled on the product.
   *
   * This method returns the variations, if any, specified (limited) by
   * the bundle item, or fall back to all enabled variations of the referenced product.
   *
   * @return \Drupal\commerce_product\Entity\ProductVariationInterface[]
   *   The product variations.
   */
  public function getVariations();

  /**
   * Gets the variation IDs.
   *
   * @return int[]
   *   The variation IDs.
   */
  public function getVariationIds();

  /**
   * Get the default variation.
   *
   * @return \Drupal\commerce_product\Entity\ProductVariationInterface
   *   The default product variation.
   */
  public function getDefaultVariation();

  /**
   * Adds a variation.
   *
   * If the bundle item does not yet hold a product reference, nothing happens.
   * So if you unsure you should propably check for existence of the product
   * reference.
   *
   * If the bundle item has a product reference, but doesn't restrict
   * the variations, nothing will happen. You can check for this
   * with hasVariations().
   *
   * @code
   * if($bundleItem->hasProduct() && $bundleItem->hasVariations()){
   *    $bundleItem->addVariation($variation)
   * } else {
   *    $bundleItem->setVariations([$variation]);
   * }
   * @endcode
   *
   * @param \Drupal\commerce_product\Entity\ProductVariationInterface $variation
   *   The variation.
   *
   * @throws \InvalidArgumentException
   *    In case the variation don't belong to the referenced product.
   *
   * @return $this
   */
  public function addVariation(ProductVariationInterface $variation);

  /**
   * Removes a variation.
   *
   * @param \Drupal\commerce_product\Entity\ProductVariationInterface $variation
   *   The variation.
   *
   * @return $this
   */
  public function removeVariation(ProductVariationInterface $variation);

  /**
   * Gets the currently selected variation, or the default variation.
   *
   * @return \Drupal\commerce_product\Entity\ProductVariationInterface
   *   The variation.
   */
  public function getCurrentVariation();

  /**
   * Gets the currently selected variation, or the default variation.
   *
   * @param \Drupal\commerce_product\Entity\ProductVariationInterface $variation
   *   The variation.
   *
   * @throws \InvalidArgumentException
   *   In case the variation passed as argument is not referenced by the bundle
   *   item.
   *
   * @return $this
   */
  public function setCurrentVariation(ProductVariationInterface $variation);

  /**
   * Sets the price of one unit of the referenced
   * product variations.
   *
   * @param \Drupal\commerce_price\Price $unit_price
   *   The unit price.
   *
   * @return \Drupal\commerce_product_bundle\Entity\BundleItemInterface
   *   The called product bundle item entity.
   */
  public function setUnitPrice(Price $unit_price);

  /**
   * Gets the price of one unit of the referenced
   * product variations.
   *
   * @return \Drupal\commerce_price\Price|null
   *   The unit price or NULL.
   */
  public function getUnitPrice();

  /**
   * Check whether the bundleItem has an own unit price.
   *
   * @return bool
   *   True it the bundle item has an own unit price set,
   *   false if not.
   */
  public function hasUnitPrice();

}

Members

Namesort descending Modifiers Type Description Overrides
AccessibleInterface::access public function Checks data value access. 9
BundleItemInterface::addVariation public function Adds a variation. 1
BundleItemInterface::getBundle public function Gets the parent bundle entity. 1
BundleItemInterface::getBundleId public function Gets the parent product bundle ID. 1
BundleItemInterface::getCreatedTime public function Gets the product bundle item creation timestamp. 1
BundleItemInterface::getCurrentVariation public function Gets the currently selected variation, or the default variation. 1
BundleItemInterface::getDefaultVariation public function Get the default variation. 1
BundleItemInterface::getMaximumQuantity public function Gets the maximum quantity of the product variations. 1
BundleItemInterface::getMinimumQuantity public function Gets the minimum quantity of the product variations. 1
BundleItemInterface::getProduct public function Get the referenced product. 1
BundleItemInterface::getProductId public function Gets the bundle item's product id. 1
BundleItemInterface::getQuantity public function Gets the bundle item quantity. 1
BundleItemInterface::getTitle public function Gets the product bundle item title. 1
BundleItemInterface::getUnitPrice public function Gets the price of one unit of the referenced product variations. 1
BundleItemInterface::getVariationIds public function Gets the variation IDs. 1
BundleItemInterface::getVariations public function Gets the product variations limited by the bundle item or enabled on the product. 1
BundleItemInterface::hasProduct public function Gets whether the bundle item has a product set or not. 1
BundleItemInterface::hasUnitPrice public function Check whether the bundleItem has an own unit price. 1
BundleItemInterface::hasVariations public function Gets whether the bundle item has restricted variations. 1
BundleItemInterface::isRequired public function Whether the product bundle item is required or not. 1
BundleItemInterface::removeVariation public function Removes a variation. 1
BundleItemInterface::setCreatedTime public function Sets the product bundle item creation timestamp. 1
BundleItemInterface::setCurrentVariation public function Gets the currently selected variation, or the default variation. 1
BundleItemInterface::setMaximumQuantity public function Sets the maximum quantity of the product variations. 1
BundleItemInterface::setMinimumQuantity public function Sets the minimum quantity of the product variations. 1
BundleItemInterface::setProduct public function Set the referenced product. 1
BundleItemInterface::setQuantity public function Sets the quantity for the bundle item. 1
BundleItemInterface::setRequired public function Set whether the product bundle item is required or not. 1
BundleItemInterface::setTitle public function Sets the product bundle item title. 1
BundleItemInterface::setUnitPrice public function Sets the price of one unit of the referenced product variations. 1
BundleItemInterface::setVariations public function Sets the variations. 1
CacheableDependencyInterface::getCacheContexts public function The cache contexts associated with this object. 34
CacheableDependencyInterface::getCacheMaxAge public function The maximum age for which this object may be cached. 34
CacheableDependencyInterface::getCacheTags public function The cache tags associated with this object. 27
EntityChangedInterface::getChangedTime public function Gets the timestamp of the last entity change for the current translation.
EntityChangedInterface::getChangedTimeAcrossTranslations public function Gets the timestamp of the last entity change across all translations.
EntityChangedInterface::setChangedTime public function Sets the timestamp of the last entity change for the current translation.
EntityInterface::bundle public function Gets the bundle of the entity. 2
EntityInterface::create public static function Constructs a new entity object, without permanently saving it. 2
EntityInterface::createDuplicate public function Creates a duplicate of the entity. 2
EntityInterface::delete public function Deletes an entity permanently. 2
EntityInterface::enforceIsNew public function Enforces an entity to be new. 2
EntityInterface::getCacheTagsToInvalidate public function Returns the cache tags that should be used to invalidate caches. 2
EntityInterface::getConfigDependencyKey public function Gets the key that is used to store configuration dependencies. 2
EntityInterface::getConfigDependencyName public function Gets the configuration dependency name. 2
EntityInterface::getConfigTarget public function Gets the configuration target identifier for the entity. 2
EntityInterface::getEntityType public function Gets the entity type definition. 2
EntityInterface::getEntityTypeId public function Gets the ID of the type of the entity. 2
EntityInterface::getOriginalId public function Gets the original ID. 2
EntityInterface::getTypedData public function Gets a typed data object for this entity object. 2
EntityInterface::hasLinkTemplate public function Indicates if a link template exists for a given key. 2
EntityInterface::id public function Gets the identifier. 2
EntityInterface::isNew public function Determines whether the entity is new. 2
EntityInterface::label public function Gets the label of the entity. 2
EntityInterface::language public function Gets the language of the entity. 2
EntityInterface::link Deprecated public function Deprecated way of generating a link to the entity. See toLink(). 2
EntityInterface::load public static function Loads an entity. 2
EntityInterface::loadMultiple public static function Loads one or more entities. 2
EntityInterface::postCreate public function Acts on a created entity before hooks are invoked. 2
EntityInterface::postDelete public static function Acts on deleted entities before the delete hook is invoked. 2
EntityInterface::postLoad public static function Acts on loaded entities. 3
EntityInterface::postSave public function Acts on a saved entity before the insert or update hook is invoked. 2
EntityInterface::preCreate public static function Changes the values of an entity before it is created. 2
EntityInterface::preDelete public static function Acts on entities before they are deleted and before hooks are invoked. 2
EntityInterface::preSave public function Acts on an entity before the presave hook is invoked. 2
EntityInterface::referencedEntities public function Gets a list of entities referenced by this entity. 2
EntityInterface::save public function Saves an entity permanently. 2
EntityInterface::setOriginalId public function Sets the original ID. 2
EntityInterface::toArray public function Gets an array of all property values. 3
EntityInterface::toLink public function Generates the HTML for a link to this entity. 2
EntityInterface::toUrl public function Gets the URL object for the entity. 2
EntityInterface::uriRelationships public function Gets a list of URI relationships supported by this entity. 2
EntityInterface::url Deprecated public function Gets the public URL for this entity. 2
EntityInterface::urlInfo Deprecated public function Gets the URL object for the entity. 2
EntityInterface::uuid public function Gets the entity UUID (Universally Unique Identifier). 2
EntityOwnerInterface::getOwner public function Returns the entity owner's user entity. 1
EntityOwnerInterface::getOwnerId public function Returns the entity owner's user ID. 1
EntityOwnerInterface::setOwner public function Sets the entity owner's user entity. 1
EntityOwnerInterface::setOwnerId public function Sets the entity owner's user ID. 1
RefinableCacheableDependencyInterface::addCacheableDependency public function Adds a dependency on an object: merges its cacheability metadata. 1
RefinableCacheableDependencyInterface::addCacheContexts public function Adds cache contexts. 1
RefinableCacheableDependencyInterface::addCacheTags public function Adds cache tags. 1
RefinableCacheableDependencyInterface::mergeCacheMaxAge public function Merges the maximum age (in seconds) with the existing maximum age. 1