Author: Adam Piotrowski (adam@wellcommerce.org)
Inheritance: extends WellCommerce\Bundle\DoctrineBundle\Entity\EntityInterface, extends WellCommerce\Bundle\CoreBundle\Entity\TimestampableInterface, extends WellCommerce\Bundle\AvailabilityBundle\Entity\AvailabilityAwareInterface, extends WellCommerce\Bundle\ProductBundle\Entity\ProductAwareInterface, extends WellCommerce\Bundle\AppBundle\Entity\HierarchyAwareInterface, extends WellCommerce\Bundle\MediaBundle\Entity\MediaAwareInterface
Ejemplo n.º 1
0
 public function getVariantOptions(VariantInterface $variant) : array
 {
     $options = [];
     $variant->getOptions()->map(function (VariantOptionInterface $variantOption) use(&$options) {
         $attribute = $variantOption->getAttribute();
         $attributeValue = $variantOption->getAttributeValue();
         $options[$attribute->translate()->getName()] = $attributeValue->translate()->getName();
     });
     return $options;
 }
 public function __construct(ProductInterface $product, VariantInterface $variant = null, $quantity, \Exception $previous)
 {
     $message = sprintf('Cannot add item with id: "%s", attribute: "%s" and quantity: "%s" to cart', $product->getId(), null === $variant ? 0 : $variant->getId(), $quantity);
     parent::__construct($message, $previous->getCode(), $previous);
 }
 protected function getVariantId(VariantInterface $variant = null)
 {
     return !$variant instanceof VariantInterface ? 0 : $variant->getId();
 }
 /**
  * Calculates new amount for attribute
  *
  * @param VariantInterface $variant
  * @param                           $amount
  *
  * @return float
  */
 protected function calculateAttributePrice(VariantInterface $variant, $amount)
 {
     $modifierType = $variant->getModifierType();
     $modifierValue = $variant->getModifierValue();
     switch ($modifierType) {
         case '+':
             $amount = $amount + $modifierValue;
             break;
         case '-':
             $amount = $amount - $modifierValue;
             break;
         case '%':
             $amount = $amount * ($modifierValue / 100);
             break;
     }
     return round($amount, 2);
 }