Example #1
0
 /**
  * render
  *
  * @param string $id
  * @param string $name
  * @param \Extcode\Cart\Domain\Model\Product\Product $product
  *
  * @return string
  */
 public function render($id = '', $name = '', \Extcode\Cart\Domain\Model\Product\Product $product)
 {
     $currencyViewHelper = $this->objectManager->get(\Extcode\Cart\ViewHelpers\Format\CurrencyViewHelper::class);
     $currencyViewHelper->initialize();
     $currencyViewHelper->setRenderingContext($this->renderingContext);
     $out = '';
     $out .= '<select id="' . $id . '" name="' . $name . '">';
     foreach ($product->getBeVariants() as $beVariant) {
         /**
          * @var \Extcode\Cart\Domain\Model\Product\BeVariant $beVariant
          */
         $currencyViewHelper->setRenderChildrenClosure(function () use($beVariant) {
             return $beVariant->getPriceCalculated();
         });
         $regularPrice = $currencyViewHelper->render();
         $currencyViewHelper->setRenderChildrenClosure(function () use($beVariant) {
             return $beVariant->getBestPriceCalculated();
         });
         $specialPrice = $currencyViewHelper->render();
         $optionLabelArray = [];
         if ($product->getBeVariantAttribute1()) {
             $optionLabelArray[] = $beVariant->getBeVariantAttributeOption1()->getTitle();
         }
         if ($product->getBeVariantAttribute2()) {
             $optionLabelArray[] = $beVariant->getBeVariantAttributeOption2()->getTitle();
         }
         if ($product->getBeVariantAttribute3()) {
             $optionLabelArray[] = $beVariant->getBeVariantAttributeOption3()->getTitle();
         }
         $optionLabel = join(' - ', $optionLabelArray);
         $value = 'value="' . $beVariant->getUid() . '"';
         $data = 'data-regular-price="' . $regularPrice . '"';
         if ($regularPrice != $specialPrice) {
             $data .= ' data-special-price="' . $specialPrice . '"';
         }
         $out .= '<option ' . $value . ' ' . $data . '>' . $optionLabel . '</option>';
     }
     $out .= '</select>';
     return $out;
 }
Example #2
0
 /**
  * @test
  */
 public function setBeVariantAttribute2SetsBeVariantAttribute2()
 {
     $beVariantAttribute = new \Extcode\Cart\Domain\Model\Product\BeVariantAttribute();
     $this->product->setBeVariantAttribute2($beVariantAttribute);
     $this->assertSame($beVariantAttribute, $this->product->getBeVariantAttribute2());
 }