You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification
<?php
defined('_JEXEC') or die;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Factory;
if (!class_exists('VmConfig')) {
require(JPATH_ADMINISTRATOR . '/components/com_virtuemart/helpers/config.php');
}
VmConfig::loadConfig();
if (!class_exists('VmModel')) {
require(JPATH_ADMINISTRATOR . '/components/com_virtuemart/helpers/vmmodel.php');
}
$productId = Factory::getApplication()->input->getInt('virtuemart_product_id', 0);
if ($productId > 0) {
$db = Factory::getDbo();
$timezone = Factory::getConfig()->get('offset');
$date = new DateTime('now', new DateTimeZone($timezone));
$today = $date->format('Y-m-d');
$query = $db->getQuery(true)
->select('price, date')
->from($db->qn('#__virtuemart_product_price_history'))
->where('virtuemart_product_id = ' . (int)$productId)
->where('date >= DATE_SUB(' . $db->quote($today) . ', INTERVAL 30 DAY)')
->where('date < ' . $db->quote($today)) // tylko ceny sprzed dzisiaj
->order('price ASC, date ASC')
->setLimit(1);
$db->setQuery($query);
$lowestPriceData = $db->loadAssoc();
$productModel = VmModel::getModel('product');
$product = $productModel->getProduct($productId, true, false, false, true);
$prices = $productModel->getPrice($product, [], 1);
if (!empty($prices['discountAmount']) && $prices['discountAmount'] != 0 && !empty($lowestPriceData) && $lowestPriceData['price'] > 0) {
$currency = CurrencyDisplay::getInstance();
$convertedLowestPrice = $currency->priceDisplay($lowestPriceData['price']);
$lowestPriceDate = date('d.m.Y', strtotime($lowestPriceData['date']));
echo '<div class="uk-text-small uk-margin-small-top"><span>'. Text::_('LOWEST_PRICE').':</span> <span>' . $convertedLowestPrice . '</span></div>';
echo '<div class="uk-text-small"><span>'. Text::_('LOWEST_DATE').':</span> <span>' . $lowestPriceDate . '</span></div>';
}
}
<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="4.0" client="site" method="upgrade">
<name>mod_lowestprice</name>
<author>666</author>
<version>1.0.0</version>
<description>Module for displaying the lowest price in the last 30 days on VirtueMart product page</description>
<files>
<filename module="mod_lowestprice">mod_lowestprice.php</filename>
</files>
</extension>
You cannot view this attachment.CREATE TABLE IF NOT EXISTS `#__virtuemart_product_price_history` (
`id` INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
`virtuemart_product_id` INT UNSIGNED NOT NULL,
`price` DECIMAL(15,5) NOT NULL DEFAULT 0,
`date` DATE NOT NULL,
UNIQUE KEY `unique_product_date` (`virtuemart_product_id`, `date`),
INDEX (`virtuemart_product_id`),
INDEX (`date`)
);
<?php
define('JPATH_BASE', realpath(__DIR__ . '/..'));
define('_JEXEC', 1);
require_once JPATH_BASE . '/includes/app.php';
use Joomla\CMS\Factory;
$app = Factory::getApplication('site');
if (!class_exists('VmConfig')) {
require(JPATH_BASE . '/administrator/components/com_virtuemart/helpers/config.php');
}
VmConfig::loadConfig();
if (!class_exists('VmModel')) {
require(JPATH_BASE . '/administrator/components/com_virtuemart/helpers/vmmodel.php');
}
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('virtuemart_product_id')
->from('#__virtuemart_products');
$db->setQuery($query);
$products = $db->loadColumn();
$productModel = VmModel::getModel('product');
$date = date('Y-m-d');
foreach ($products as $product_id) {
$product = $productModel->getProduct($product_id, true, false, false, true);
$prices = $productModel->getPrice($product, [], 1);
$finalPrice = isset($prices['salesPrice']) ? $prices['salesPrice'] : 0;
// Pobierz ostatnio zapisaną cenę dla tego produktu
$query = $db->getQuery(true)
->select('price')
->from('#__virtuemart_product_price_history')
->where('virtuemart_product_id = ' . (int)$product_id)
->order('date DESC')
->setLimit(1);
$db->setQuery($query);
$lastSavedPrice = $db->loadResult();
if (is_null($lastSavedPrice) || (float)$finalPrice < (float)$lastSavedPrice) {
$queryInsert = "
INSERT INTO #__virtuemart_product_price_history (virtuemart_product_id, price, date)
VALUES (" . (int)$product_id . ", " . (float)$finalPrice . ", " . $db->quote($date) . ")
ON DUPLICATE KEY UPDATE price = VALUES(price)
";
$db->setQuery($queryInsert);
$db->execute();
}
}
$queryDelete = $db->getQuery(true)
->delete('#__virtuemart_product_price_history')
->where('date < DATE_SUB(CURDATE(), INTERVAL 30 DAY)');
$db->setQuery($queryDelete);
$db->execute();
echo '<script>window.location.href = "/";</script>';
echo '<noscript><meta http-equiv="refresh" content="0; url=/" /></noscript>';
exit;
<?php
$db = JFactory::getDbo();
$today = date('Y-m-d');
$query = $db->getQuery(true)
->select('price, date')
->from('#__virtuemart_product_price_history')
->where('virtuemart_product_id = ' . (int)$product->virtuemart_product_id)
->where('date >= DATE_SUB(' . $db->quote($today) . ', INTERVAL 30 DAY)')
->where('date < ' . $db->quote($today))
->order('price ASC, date ASC')
->setLimit(1);
$db->setQuery($query);
$lowestPriceData = $db->loadAssoc();
if ($product->prices['discountAmount'] != 0 && !empty($lowestPriceData) && $lowestPriceData['price'] > 0):
$currency = CurrencyDisplay::getInstance();
$convertedLowestPrice = $currency->priceDisplay($lowestPriceData['price']);
$lowestPriceDate = date('d.m.Y', strtotime($lowestPriceData['date']));
?>
<div class="ominibus">
The lowest price in the last 30 days before the promotion:
<strong><?php echo $convertedLowestPrice; ?></strong><br>
The day was in force: <strong><?php echo $lowestPriceDate; ?></strong>
</div>
<?php endif; ?>
ALTER TABLE `#__virtuemart_product_prices`
ADD COLUMN `final_price` decimal(15,5) NOT NULL DEFAULT 0 AFTER `product_override_price`;
case 'product_price':
(...)
break;
case 'product_price':
$ff_select_price = ' , IF(pp.override, pp.product_override_price, pp.product_price) as product_price, pp.final_price ';
$orderBy = ' ORDER BY pp.`final_price` ' . $filterOrderDir . ', p.`virtuemart_product_id` ' . $filterOrderDir;
$joinPrice = TRUE;
break;
<?php
define('_JEXEC', 1);
require_once __DIR__ . '/includes/app.php';
$app = Joomla\CMS\Factory::getApplication('site');
if (!class_exists('VmConfig')) {
require(JPATH_ADMINISTRATOR . '/components/com_virtuemart/helpers/config.php');
}
VmConfig::loadConfig();
if (!class_exists('VmModel')) {
require(JPATH_ADMINISTRATOR . '/components/com_virtuemart/helpers/vmmodel.php');
}
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('virtuemart_product_id')
->from('#__virtuemart_products');
$db->setQuery($query);
$products = $db->loadColumn();
$productModel = VmModel::getModel('product');
foreach ($products as $product_id) {
$product = $productModel->getProduct($product_id, true, true, true);
$prices = $productModel->getPrice($product, [], 1);
$finalPrice = isset($prices['salesPrice']) ? $prices['salesPrice'] : 0;
$queryUpdate = $db->getQuery(true)
->update('#__virtuemart_product_prices')
->set('final_price = ' . (float)$finalPrice)
->where('virtuemart_product_id = ' . (int)$product_id);
$db->setQuery($queryUpdate);
$db->execute();
}
case 'product_price':
(...)
break;
case 'product_price':
$orderBy = ' ORDER BY IF(pp.product_override_price > 0 AND pp.override = 1, pp.product_override_price, pp.product_price) ' . $filterOrderDir . ', p.`virtuemart_product_id` ' . $filterOrderDir;
$ff_select_price = ' , IF(pp.override = 1 AND pp.product_override_price > 0, pp.product_override_price, pp.product_price) as product_price ';
$joinPrice = TRUE;
break;
Quote from: Dud3 on January 20, 2025, 06:38:14 AMI've overhauled the complete data receiving part - the Virtuemart Models are now used.
Customfields are now indexed if they have the search parameter enabled.
Breakdesign CustomFilter customfields are supported too.
Added a new plugin to allow you (or show you) how to access the indexing part and customize it to your needs.
More or less all Virtuemart product/category/manufacturer variables are there available.
https://github.com/Dudebaker/Virtuemart-Finder
Page created in 0.149 seconds with 16 queries.