Skip to content

Instantly share code, notes, and snippets.

@samnabi
Last active September 10, 2016 19:58
Show Gist options
  • Save samnabi/2f83677027e27232681b03c080854ac1 to your computer and use it in GitHub Desktop.
Save samnabi/2f83677027e27232681b03c080854ac1 to your computer and use it in GitHub Desktop.
Product page with combined dropdown for all variants (Shopkit 1.0.5)
<?php
// Tested with Shopkit 1.0.5. This template may break in future releases.
// Save this file as /site/templates/product.php to override the default Product template included with Shopkit.
snippet('header') ?>
<?php snippet('breadcrumb') ?>
<?php if ($page->hasImages()) snippet('slider',['photos'=>$page->images()]) ?>
<?php if ($page->brand()->isNotempty()) { ?>
<small class="brand" property="brand"><?= $page->brand() ?></small>
<?php } ?>
<h1 dir="auto"><?= $page->title()->html() ?></h1>
<div class="uk-grid uk-grid-width-medium-1-2">
<div>
<section>
<?= $page->text()->kirbytext()->bidi() ?>
<?php if (count($tags)) { ?>
<p dir="auto">
<?php foreach ($tags as $tag) { ?>
<a href="<?= $site->url().'/search/?q='.urlencode($tag) ?>">#<?= $tag ?></a>
<?php } ?>
</p>
<?php } ?>
</section>
</div>
<?php if (count($variants)) { ?>
<section class="variants">
<form method="post" action="<?= url('shop/cart') ?>">
<!-- Schema.org markup -->
<?php if($page->hasImages()) { ?>
<link property="image" content="<?= $page->images()->first()->url() ?>" />
<?php } ?>
<link property="brand" content="<?= $page->brand() ?>" />
<link property="name" content="<?= $page->title() ?>" />
<input type="hidden" name="action" value="add">
<select name="id">
<option selected disabled>Size</option>
<?php foreach ($variants as $variant) { ?>
<?php if ($variant->hasOptions) { ?>
<?php foreach (str::split($variant->options()) as $option) { ?>
<option <?php e(inStock($variant),'','disabled') ?> value="<?= $page->uri() ?>::<?= str::slug($variant->name()) ?>::<?= str::slug($option) ?>">
<?= $variant->name() ?>:
<?= str::ucfirst($option) ?>
(<?= $variant->priceText ?>)
</option>
<?php } ?>
<?php } else { ?>
<option <?php e(inStock($variant),'','disabled') ?> value="<?= $page->uri() ?>::<?= str::slug($variant->name()) ?>::">
<?= $variant->name() ?>
(<?= $variant->priceText ?>)
</option>
<?php } ?>
<?php } ?>
</select>
<button type="submit" name="submit">Add to cart</button>
</form>
</section>
<?php } ?>
</div>
<?php snippet('list.related') ?>
<?php snippet('footer') ?>
@samnabi
Copy link
Author

samnabi commented Sep 10, 2016

screen shot 2016-09-10 at 15 57 57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment