Skip to content

Commit

Permalink
Update FlexSlider.ss re: PreviewImage
Browse files Browse the repository at this point in the history
Update FlexSlider.ss include to show either ProductImages (if they exist) or PreviewImage.

fixes dynamic#113
  • Loading branch information
muskie9 committed Feb 13, 2015
1 parent f327841 commit d28b752
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 27 deletions.
14 changes: 10 additions & 4 deletions code/extensions/FoxyStripeSiteConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class FoxyStripeSiteConfig extends DataExtension{

private static $db = array(
'StoreName' => 'Varchar(255)',
'StoreKey' => 'Varchar(255)',
'StoreKey' => 'Varchar(60)',
'MultiGroup' => 'Boolean',
'ProductLimit' => 'Int',
'CartValidation' => 'Boolean'
Expand All @@ -15,6 +15,12 @@ class FoxyStripeSiteConfig extends DataExtension{
'ProductLimit' => 10
);

public function populateDefaults(){
parent::populateDefaults();

$this->owner->StoreKey = FoxyCart::setStoreKey();
}


public function updateCMSFields(FieldList $fields){

Expand All @@ -40,9 +46,9 @@ public function updateCMSFields(FieldList $fields){
CheckboxField::create('CartValidation')
->setTitle('Enable Cart Validation')
->setDescription('You must <a href="https://admin.foxycart.com/admin.php?ThisAction=EditAdvancedFeatures#use_cart_validation" target="_blank">enable cart validation</a> in the FoxyCart admin.'),
TextField::create('StoreKey')
ReadonlyField::create('StoreKey')
->setTitle('FoxyCart API Key')
->setDescription('copy/paste from FoxyCart'),
->setDescription('copy/paste to FoxyCart'),
ReadonlyField::create('SSOLink', 'Single Sign On URL', self::getSSOLink())
->setDescription('copy/paste to FoxyCart')
);
Expand Down Expand Up @@ -88,4 +94,4 @@ private static function getDataFeedLink() {
return Director::absoluteBaseURL()."foxystripe/";
}

}
}
32 changes: 27 additions & 5 deletions code/model/FoxyCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,32 @@

class FoxyCart extends Object {

public static function store_key_warning(){
private static $keyPrefix = 'dYnm1c';

public static function store_key_warning()
{
$warning = null;
if(self::getStoreKey()===null){
if (self::getStoreKey() === null) {
$warning = 'Must define FoxyCart Store Key in your site settings in the cms';
}
return $warning;
}

public static function setStoreKey($length = 54, $count = 0){
$charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$charset .= strtotime('now');
$strLength = strlen($charset);
$str = '';
while($count < $length){
$str .= $charset[mt_rand(0, $strLength-1)];
$count++;
}
$str = base64_encode($str);
$str = substr($str,0,$length);
$key = self::getKeyPrefix()."$str";
return $key;
}

public static function getStoreKey(){
$config = SiteConfig::current_site_config();
if($config->StoreKey){
Expand All @@ -30,15 +48,15 @@ public static function store_name_warning(){
}
return $warning;
}

public static function getFoxyCartStoreName(){
$config = SiteConfig::current_site_config();
if($config->StoreName){
return $config->StoreName;
}
return null;
}

public static function FormActionURL() {
return sprintf('https://%s.foxycart.com/cart', self::getFoxyCartStoreName() );
}
Expand Down Expand Up @@ -106,5 +124,9 @@ public static function putCustomer($Member = null) {

return self::getAPIRequest($foxyData);
}


private static function getKeyPrefix(){
return self::$keyPrefix;
}

}
33 changes: 15 additions & 18 deletions templates/Includes/FlexSlider.ss
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<div class="flexslider" id="slider">
<ul class="slides">
<% if $PreviewImage %>
<li>
<% with $PreviewImage %>
<a href="{$URL}" rel="shadowbox">
<img src="{$URL}">
</a>
<% end_with %>
</li>
<% end_if %>
<% if $ProductImages %>
<% loop $ProductImages %>
<li>
Expand All @@ -17,25 +8,31 @@
</a>
</li>
<% end_loop %>
<% else_if $PreviewImage %>
<li>
<% with $PreviewImage %>
<a href="{$URL}" rel="shadowbox">
<img src="{$URL}">
</a>
<% end_with %>
</li>
<% end_if %>
</ul>
</div>
<div class="flexslider" id="carousel">
<ul class="slides">
<% if $ProductImages %>
<% if $PreviewImage %>
<li>
<% with $PreviewImage %>
<img src="{$PaddedImage(75,75).URL}">
<% end_with %>
</li>
<% end_if %>

<% loop $ProductImages %>
<li>
<img src="{$Image.PaddedImage(75,75).URL}" alt="$Name.XML">
</li>
<% end_loop %>
<% else_if $PreviewImage %>
<li>
<% with $PreviewImage %>
<img src="{$PaddedImage(75,75).URL}">
<% end_with %>
</li>
<% end_if %>
</ul>
</div>
</div>

0 comments on commit d28b752

Please sign in to comment.