/**
  * Returns a human readable name for a purchasable, whether Product or
  * Variant is, with all needed information. This value is unique per each
  * type of purchasable element.
  *
  * @param PurchasableInterface $purchasable Purchasable to get name from
  * @param string               $separator   Separator string for product variant options
  *
  * @return string Purchasable name
  */
 public function getPurchasableName(PurchasableInterface $purchasable, $separator = self::DEFAULT_SEPARATOR)
 {
     if ($purchasable instanceof ProductInterface) {
         return $purchasable->getName();
     }
     /**
      * @var VariantInterface $purchasable
      */
     $productName = $purchasable->getProduct()->getName();
     foreach ($purchasable->getOptions() as $option) {
         /**
          * @var ValueInterface $option
          */
         $productName .= $separator . $option->getAttribute()->getName() . ' ' . $option->getValue();
     }
     return $productName;
 }
Exemplo n.º 2
0
 /**
  * Given a purchasable, resolve the name.
  *
  * @param PurchasableInterface $purchasable Purchasable
  * @param string               $separator   Separator
  *
  * @return string Name resolved
  */
 public function resolveName(PurchasableInterface $purchasable, $separator = self::DEFAULT_SEPARATOR)
 {
     $namespace = $this->getPurchasableNamespace();
     if (!$purchasable instanceof $namespace) {
         return false;
     }
     /**
      * @var $purchasable VariantInterface
      */
     $variantName = $purchasable->getProduct()->getName();
     foreach ($purchasable->getOptions() as $option) {
         /**
          * @var ValueInterface $option
          */
         $variantName .= $separator . $option->getAttribute()->getName() . ' ' . $option->getValue();
     }
     return $variantName;
 }
Exemplo n.º 3
0
 /**
  * Returns a homan readable name for a purchasable, whether Product or Variant
  *
  * @param PurchasableInterface $purchasable Purchasable to get name from
  * @param string               $separator   Separator string for product variant options
  *
  * @return string
  */
 public function getPurchasableName(PurchasableInterface $purchasable, $separator = ' - ')
 {
     if ($purchasable instanceof ProductInterface) {
         /**
          * @var ProductInterface $purchasable
          */
         $productName = $purchasable->getName();
     } else {
         /**
          * @var VariantInterface $purchasable
          */
         $productName = $purchasable->getProduct()->getName();
         foreach ($purchasable->getOptions() as $option) {
             /**
              * @var ValueInterface $option
              */
             $productName .= $separator . $option->getAttribute()->getName() . ' ' . $option->getName();
         }
     }
     return $productName;
 }