/** * @return HtmlTagBuilder */ protected function createCheckoutConfirmation() { // checkout confirmation $confirmation = new HtmlTagBuilder('div'); $cartView = $this->renderCart(); $checkoutSummary = $this->renderCheckoutSummary(); $confirmation->append($cartView); $confirmation->append($checkoutSummary); return $confirmation; }
/** * Cart Table * * @param CartWithShipping $cart * @param bool $edit - show edit input fields * * @return HtmlTagBuilder */ public function renderCart($cart, $edit = false) { $cartWrapper = new HtmlTagBuilder('div', array('class' => 'cartOverview')); $cartTable = new HtmlTagBuilder('table', array('class' => 'cartTable')); $cartTable->append($this->createTableHeader()); $cartWrapper->append($cartTable); // empty cart if ($cart->totalUniqueItems() === 0) { $this->addEmptyCartRow($cartTable); } else { /** @var CartItem $item */ foreach ($cart->all() as $item) { $cartTable->append($this->renderCartRow($edit, $item)); } $this->addCartSummary($cart, $cartTable); } return $cartWrapper; }
/** * Creates an html tag object that output build the basis for the javascript * responsive image lib * * @param string|\Render\APIs\APIv1\MediaImage $image * The media image object or its id * @param array $imageCfg * The image manipulations; The following keys/values are supported * # 'crop' => array('x' => int, 'y' => int, 'width' => int, 'height' => int) * # 'resize' => array('width' => int, 'height' => int) * # 'quality' => int * @param array attributes * A set of additional tag attributes (key -> attribute name, value -> attribute value) * @return \Rukzuk\Modules\HtmlTagBuilder */ public function getImageTag($image = null, $imageCfg = null, $attributes = null) { // wrapper $wrapper = new HtmlTagBuilder('div', array('class' => 'responsiveImageWrapper')); // image tag $imgTag = new HtmlTagBuilder('img', array('alt' => '')); $imgTag->set($attributes); $imgTag->addClass('imgSize'); // fill height element which helps to keep aspect ratio of image (using %-padding technique) $fillHeight = new HtmlTagBuilder('div', array('class' => 'fillHeight')); try { if (is_string($image)) { // get the image object if a image id was given $image = $this->api->getMediaItem($image)->getImage(); } } catch (Exception $e) { } // we have a image (object) if (is_object($image)) { // height in percent of the width (used for padding trick) $origWidth = $image->getOriginalWidth(); $origHeight = $image->getOriginalHeight(); $origHeightRatio = $origHeight / $origWidth * 100; // create the image urls for each of the pre-defined and most common device resolutions $imgUrls = $this->getResponsiveImageUrls($image->getMediaItem(), $imageCfg); // provide big, not cropped image, // used in image cropper (panzoom) and for rz_lightbox try { $image->resetOperations(); $image = $image->resizeScale(ResponsiveImageBuilder::$maxResponsiveImageResolution); $imgTag->set('data-cms-origsrc', $image->getUrl()); } catch (Exception $e) { // do nothing } // indicate that we have an actual image $wrapper->addClass('hasImage'); // data for js image replacement code (lazy sizes) // build src set $srcSet = array(); foreach ($imgUrls as $w => $u) { $srcSet[] = $u . ' ' . $w . 'w'; } $imgTag->set(array('data-sizes' => 'auto', 'data-srcset' => implode(', ', $srcSet))); $imgTag->addClass('lazyload'); $imgTag->addClass('responsiveImage'); // set default image (smallest resolution LQIP for fast responses) $image->resetOperations(); $preloadSrc = $this->getResponsiveImageUrl($image, $imageCfg, ResponsiveImageBuilder::$previewResponsiveImageResolution); $imgTag->set('src', $preloadSrc); // set fill height value $imgHeight = $this->api->getFormValue($this->unit, 'imgHeight', '0%'); // use original aspect ratio as height if 0% $fillHeightPaddingBottom = $imgHeight == '0%' ? sprintf('%F', $origHeightRatio) . '%' : $imgHeight; } else { // show a blank image $imgTag->addClass('blankImgPlaceholder')->set('src', $this->getPlaceholderUrl()); // set fill height value - use 50% if it is 0% (original image) because blank image has no size (it is a background) $blankHeight = $this->api->getFormValue($this->unit, 'imgHeight', '0%'); // use 50% as height, because we don't have a original aspect ratio $fillHeightPaddingBottom = $blankHeight == '0%' ? '50%' : $blankHeight; } $fillHeight->set('style', 'padding-bottom: ' . $fillHeightPaddingBottom . ';'); $wrapper->append($imgTag); $wrapper->append($fillHeight); return $wrapper; }
/** * @param $variants * @return HtmlTagBuilder */ private function buildVariantSelect($variants) { $variantSelect = new HtmlTagBuilder('select', array('name' => 'variant', 'class' => 'pd-addToCartVariants')); foreach ($variants as $variant) { $variantSelect->append(new HtmlTagBuilder('option', array('value' => $variant), array($variant))); } return $variantSelect; }
/** * @param HeadAPI $api * @param Unit $unit * @param HtmlTagBuilder $wrapper */ protected function showErrors($api, $unit, $wrapper) { $errors = $this->getUnitContext($api, $unit, 'errors', array()); foreach ($errors as $errorMessage) { $wrapper->append(HtmlTagBuilder::div($errorMessage)->set('class', 'errorMessage')); } }