protected function getVariantId(ProductAttributeInterface $attribute = null)
 {
     if (null === $attribute) {
         return 0;
     }
     return $attribute->getId();
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function getWeight()
 {
     if (null === $this->attribute) {
         return $this->product->getWeight();
     }
     return $this->attribute->getWeight();
 }
 public function __construct(ProductInterface $product, ProductAttributeInterface $attribute = null, $quantity, \Exception $previous)
 {
     $message = sprintf('Cannot add item with id: "%s", attribute: "%s" and quantity: "%s" to cart', $product->getId(), null === $attribute ? 0 : $attribute->getId(), $quantity);
     parent::__construct($message, $previous->getCode(), $previous);
 }
 /**
  * Returns the attribute's data
  *
  * @param ProductAttributeInterface $productAttribute
  *
  * @return array
  */
 protected function getAttributeData(ProductAttributeInterface $productAttribute)
 {
     $sellPrice = $productAttribute->getSellPrice();
     $baseCurrency = $sellPrice->getCurrency();
     return ['id' => $productAttribute->getId(), 'finalPriceGross' => $this->currencyHelper->convertAndFormat($sellPrice->getFinalGrossAmount(), $baseCurrency), 'sellPriceGross' => $this->currencyHelper->convertAndFormat($sellPrice->getGrossAmount(), $baseCurrency), 'discountPriceGross' => $this->currencyHelper->convertAndFormat($sellPrice->getDiscountedGrossAmount(), $baseCurrency), 'stock' => $productAttribute->getStock(), 'symbol' => $productAttribute->getSymbol()];
 }
 /**
  * Calculates new amount for attribute
  *
  * @param ProductAttributeInterface $productAttribute
  * @param                           $amount
  *
  * @return float
  */
 protected function calculateAttributePrice(ProductAttributeInterface $productAttribute, $amount)
 {
     $modifierType = $productAttribute->getModifierType();
     $modifierValue = $productAttribute->getModifierValue();
     switch ($modifierType) {
         case '+':
             $amount = $amount + $modifierValue;
             break;
         case '-':
             $amount = $amount - $modifierValue;
             break;
         case '%':
             $amount = $amount * ($modifierValue / 100);
             break;
     }
     return round($amount, 2);
 }