/** * @param string $id * @param PageAbstract $product */ public function __construct($id, PageAbstract $product, $quantity) { $variant = false; // Break cart ID into uri, variant, and option (:: is used as a delimiter) $id_array = explode('::', $id); // Set variant and option $variantName = $id_array[1]; $variants = $product->variants()->yaml(); foreach ($variants as $key => $array) { if (str::slug($array['name']) === $variantName) { $variant = $variants[$key]; } } $this->id = $id; $this->sku = $variant['sku']; $this->uri = $product->uri(); $this->name = $product->title()->value; $this->variant = str::slug($variant['name']); $this->option = $id_array[2]; $this->amount = $variant['price']; $this->sale_amount = salePrice($variant); $this->weight = $variant['weight']; $this->quantity = $quantity; $this->noshipping = $product->noshipping()->value; $this->notax = $product->notax()->value; }
<h1 class="product__title"><?php echo $page->title()->html(); ?> </h1> <?php if (count($variants)) { ?> <?php foreach ($variants as $variant) { ?> <div class="product__price"> <?php if ($saleprice = salePrice($variant)) { echo '<ins class="price--sale">' . formatPrice($saleprice) . '</ins> '; echo '<del class="price--crossed">' . formatPrice($variant->price()->value) . '</del>'; } else { echo formatPrice($variant->price()->value); } ?> </div> <div class="product__options"> <form method="post" action="<?php echo url('shop/cart'); ?> "> <!-- Hidden fields -->
if (!$featuredVariant) { $featuredVariant = $variant; $featuredPrice = $variant->price()->value; $featuredSalePrice = salePrice($variant); continue; } // For each variant, override the price as necessary if ($featuredProduct['calculation'] === 'low' and $variant->price()->value < $featuredPrice) { $featuredVariant = $variant; $featuredPrice = $variant->price()->value; $featuredSalePrice = salePrice($variant); } else { if ($featuredProduct['calculation'] === 'high' and $variant->price()->value > $featuredPrice) { $featuredVariant = $variant; $featuredPrice = $variant->price()->value; $featuredSalePrice = salePrice($variant); } } } ?> <?php // Get image if ($product->hasImages()) { $image = $product->images()->sortBy('sort', 'asc')->first(); } else { $image = $site->images()->find($site->placeholder()); } ?> <a href="<?php echo $product->url();
</a> </h3> <?php $count = $minPrice = $minSalePrice = 0; foreach ($product->variants()->toStructure() as $variant) { // Assign the first price if (!$count) { $minVariant = $variant; $minPrice = $variant->price()->value; $minSalePrice = salePrice($variant); } else { if ($variant->price()->value < $minPrice) { $minVariant = $variant; $minPrice = $variant->price()->value; $minSalePrice = salePrice($variant); } } $count++; } ?> <div class="price product-item__price"> <?php if ($minSalePrice) { $priceFormatted = '<ins class="price--sale">' . formatPrice($minSalePrice) . '</ins>'; $priceFormatted .= ' <del class="price--crossed">' . formatPrice($minPrice) . '</del>'; } else { $priceFormatted = formatPrice($minPrice); } if ($count) {
if ($product->text() != '') { ?> <p dir="auto" property="description"><?php echo $product->text()->excerpt(80); ?> </p> <?php } ?> <div dir="auto"> <?php $variants = $product->variants()->yaml(); foreach ($variants as $variant) { $pricelist[] = $variant['price']; $salepricelist[] = salePrice($variant); } $priceFormatted = is_array($pricelist) ? formatPrice(min($pricelist)) : 0; if (count($variants) > 1) { $priceFormatted = l::get('from') . ' ' . $priceFormatted; } $saleprice = $salepricelist[min(array_keys($pricelist, min($pricelist)))]; ?> <span class="uk-button uk-button-primary" property="offers" typeof="Offer"> <?php if ($saleprice) { echo formatPrice($saleprice); echo '<del>' . $priceFormatted . '</del>'; } else { echo $priceFormatted; }