SimplePortal

Customization => Custom Coding => Topic started by: vbgamer45 on March 04, 2014, 04:11:47 PM

Title: SMF Store - Block
Post by: vbgamer45 on March 04, 2014, 04:11:47 PM
Block code for Simple Portal for SMF Store (http://www.smfhacks.com/smf-store.php)
For SMF 2.0.x only
The main SMFStoreBlock function controls what is shown there are two examples below

Code: [Select]

/// examples
//  SMFStoreBlock(2,4. 'recent');
//  SMFStoreBlock(1,1. 'toprated');

/*
$category - is optional
$startHtml - is optional
$endHtml - is optional
*/

function SMFStoreBlock($rows = 4, $products = 4, $type = 'recent', $category = 0, $startHtml = '', $endHtml = '')
{
global  $smcFunc, $scripturl, $txt, $modSettings, $boardurl, $context;

$rows = (int) $rows;

if (empty($modSettings['store_url']))
$modSettings['store_url'] = $boardurl . '/store/';

// Html Header
echo $startHtml;


// Load the language files
if (loadlanguage('Store') == false)
loadLanguage('Store', 'english');

$g_manage = allowedTo('smfstore_manage');

$maxrowlevel = $rows ;
echo '<table cellspacing="0" cellpadding="5" border="0" align="center" width="100%" >
';
// Check what type it is
$query = ' ';
switch($type)
{
case 'recent':
$query = "SELECT i.ID_ITEM, i.commenttotal, i.totalratings, i.rating,
i.primaryID_PICTURE, i.productname, p.thumbfilename, i.price,i.currency,
i.qtyinstock, i.needsstock, i.date, i.views
FROM {db_prefix}store_item as i LEFT JOIN {db_prefix}store_item_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
WHERE  i.hideproduct = 0 ORDER BY i.ID_ITEM DESC LIMIT $products";
break;

case 'viewed':
$query = "SELECT i.ID_ITEM, i.commenttotal, i.totalratings, i.rating,
i.primaryID_PICTURE, i.productname, p.thumbfilename, i.price,i.currency,
i.qtyinstock, i.needsstock, i.date, i.views
FROM {db_prefix}store_item as i LEFT JOIN {db_prefix}store_item_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
WHERE  i.hideproduct = 0  ORDER BY  i.views DESC LIMIT $products";
break;

case 'mostcomments':
$query = "SELECT i.ID_ITEM, i.commenttotal, i.totalratings, i.rating,
i.primaryID_PICTURE, i.productname, p.thumbfilename, i.price,i.currency,
i.qtyinstock, i.needsstock, i.date, i.views
FROM {db_prefix}store_item as i LEFT JOIN {db_prefix}store_item_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
WHERE  i.hideproduct = 0  ORDER BY i.commenttotal DESC LIMIT $products";
break;

case 'toprated':
$query = "SELECT i.ID_ITEM, i.commenttotal, i.totalratings, i.rating,
(i.rating / i.totalratings ) AS ratingaverage,
i.primaryID_PICTURE, i.productname, p.thumbfilename, i.price,i.currency,
i.qtyinstock, i.needsstock, i.date, i.views
FROM {db_prefix}store_item as i LEFT JOIN {db_prefix}store_item_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
WHERE  i.hideproduct = 0  ORDER BY ratingaverage DESC LIMIT $products";
break;

   case 'random':
$query = "SELECT i.ID_ITEM, i.commenttotal, i.totalratings, i.rating,
i.primaryID_PICTURE, i.productname, p.thumbfilename, i.price,i.currency,
i.qtyinstock, i.needsstock, i.date, i.views
FROM {db_prefix}store_item as i LEFT JOIN {db_prefix}store_item_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
WHERE  i.hideproduct = 0 ORDER BY RAND() DESC LIMIT $products";
break;

case 'mostpurchased':

break;


}
// Execute the SQL query
$dbresult = $smcFunc['db_query']('', $query);
$rowlevel = 0;
while($row = $smcFunc['db_fetch_assoc']($dbresult))
{
if($rowlevel == 0)
echo '<tr class="windowbg2">';

echo '<td align="center"><a href="', $scripturl, '?action=store;sa=view;id=', $row['ID_ITEM'], '">', $row['productname'], '</a><br />';

if (!empty($row['primaryID_PICTURE']))
echo '<a href="', $scripturl, '?action=store;sa=view;id=', $row['ID_ITEM'], '"><img src="', $modSettings['store_url'], $row['thumbfilename'], '" alt="" /></a><br />';


echo '<span class="smalltext">';


if (!empty($modSettings['store_set_t_price']))
{

echo $txt['store_text_price'] . StoreEzformatprice($row['price'],$row['currency']) . '<br />';

}

if (!empty($modSettings['store_set_t_stock']))
{
if ($row['needsstock'])
{
if ($row['qtyinstock'] > 0)
echo $txt['store_text_instock'] . '<br />';
else
echo $txt['store_text_outofstock'] . '<br />';
}
}

if (!empty($modSettings['store_set_t_date']))
echo $txt['store_text_date'] . timeformat($row['date']) . '<br />';

if (!empty($modSettings['store_set_t_rating']))
echo $txt['store_form_rating'] . StoreEzGetStarsByPrecent(($row['totalratings'] != 0) ? ($row['rating'] / ($row['totalratings']* 5) * 100) : 0) . '<br />';


if (!empty($modSettings['store_set_t_comment']))
echo $txt['store_text_comments'] . ' (<a href="' . $scripturl . '?action=store;sa=view;id=' . $row['ID_ITEM'] . '">' . $row['commenttotal'] . '</a>)<br />';
if ($g_manage)
{

echo '&nbsp;<a href="' . $scripturl . '?action=store;sa=edititem;id=' . $row['ID_ITEM'] . '">' . $txt['store_text_edit'] . '</a>';
echo '&nbsp;<a href="' . $scripturl . '?action=store;sa=deleteitem;id=' . $row['ID_ITEM'] . '">' . $txt['store_text_delete'] . '</a>';
}

echo '</span></td>';


if($rowlevel < ($maxrowlevel-1))
$rowlevel++;
else
{
echo '</tr>';
$rowlevel = 0;
}
}
if($rowlevel !=0)
{
echo '</tr>';
}

echo '
      </table><br />';
// Free the Mysql Resoruces
$smcFunc['db_free_result']($dbresult);



// Html Footer
echo $endHtml;

}

function StoreEzformatprice($price,$currency)
{
if ($currency == 'USD')
return  '$' .  number_format($price, 2, '.', '');
else if ($currency == 'GBP')
return  '&#163;' .  number_format($price, 2, '.', '');
elseif ($currency == 'CAD')
return  '$' .  number_format($price, 2, '.', '');
elseif ($currency == 'AUD')
return  '$' .  number_format($price, 2, '.', '');
  elseif ($currency == 'ZAR')
return  'R ' .  number_format($price, 2, '-', '');
else
return $price . ' ' . $currency;

}
function StoreEzGetStarsByPrecent($percent)
{
global $settings, $txt;

if ($percent == 0)
return $txt['store_error_no_rating_selected'];
else if ($percent <= 20)
return str_repeat('<img src="' . $settings['images_url'] . '/star.gif" alt="*" border="0" />', 1);
else if ($percent <= 40)
return str_repeat('<img src="' . $settings['images_url'] . '/star.gif" alt="*" border="0" />', 2);
else if ($percent <= 60)
return str_repeat('<img src="' . $settings['images_url'] . '/star.gif" alt="*" border="0" />', 3);
else if ($percent <= 80)
return str_repeat('<img src="' . $settings['images_url'] . '/star.gif" alt="*" border="0" />', 4);
else if ($percent <= 100)
return str_repeat('<img src="' . $settings['images_url'] . '/star.gif" alt="*" border="0" />', 5);

}
Title: Re: SMF Store - Block
Post by: dan4ever on March 16, 2014, 09:10:22 AM
Hi

I tried this but got a empty box (showing nothing).
Are there any thing I should change inside the code?

/Dan
Title: Re: SMF Store - Block
Post by: dan4ever on March 16, 2014, 12:29:18 PM
Your 3 first line should be like this I think...

Code: [Select]
/// examples
//  SMFStoreBlock(2,4, 'recent');
//  SMFStoreBlock(1,1, 'toprated');

And I put in a "Random" too.

Code: [Select]

                                case 'random':
$query = "SELECT i.ID_ITEM, i.commenttotal, i.totalratings, i.rating,
i.primaryID_PICTURE, i.productname, p.thumbfilename, i.price,i.currency,
i.qtyinstock, i.needsstock, i.date, i.views
FROM {db_prefix}store_item as i LEFT JOIN {db_prefix}store_item_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
WHERE  i.hideproduct = 0 ORDER BY RAND() DESC LIMIT $products";
break;

dan4ever
Title: Re: SMF Store - Block
Post by: vbgamer45 on March 23, 2014, 09:44:23 PM
Fixed and thanks for the random idea.
SimplePortal 2.3.8 © 2008-2024, SimplePortal