我不仅仅是php的新手,我理解部分代码,但大多数人都不理解。
我正在修改一个模块,该模块根据所选类别将PrestaShop产品导出为PDF。
现在,我想要“get”函数来获取所有活动产品,而不是那些启用为“online_only”的产品。
调用产品的代码部分是:
public function getContent()
{
$context = Context::getContext();
$langmod = $context->langmod;
$products = '';
$i = 0;
foreach (Tools::getValue('categoryBox') as $osque) {
$productget = Product::getProducts(Context::getContext()->language->id, 0, 0, 'id_product', 'ASC', $osque, $active = true);
$products[$i]['products'] = $productget;
$id_lang = Context::getContext()->language->id;
$sql = '
SELECT `name`
FROM `'._DB_PREFIX_.'category_lang`
WHERE `id_category` = '.(int)$osque.'
AND `id_lang` = '.(int)$id_lang;
$name = Db::getInstance()->getValue($sql);
$products[$i]['categorie'] = $name;
$i++;
}
检查它的布尔变量是:
online_only = true
online_only = false
所以我尝试修改这行代码:
$productget = Product::getProducts(Context::getContext()->language->id, 0, 0, 'id_product', 'ASC', $osque, $active = true, $online_only = false);
但我得到一个空白页面..
任何帮助?
感谢您的时间:)
答案 0 :(得分:0)
尝试使用此覆盖(在override / classes / Product.php中):
<?php
class ProductCore extends ProductCore
{
public static function getProducts($id_lang, $start, $limit, $order_by, $order_way, $id_category = false,
$only_active = false, Context $context = null, $pdf = false)
{
if (!$context)
$context = Context::getContext();
$front = true;
if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
$front = false;
if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way))
die (Tools::displayError());
if ($order_by == 'id_product' || $order_by == 'price' || $order_by == 'date_add' || $order_by == 'date_upd')
$order_by_prefix = 'p';
else if ($order_by == 'name')
$order_by_prefix = 'pl';
else if ($order_by == 'position')
$order_by_prefix = 'c';
if (strpos($order_by, '.') > 0)
{
$order_by = explode('.', $order_by);
$order_by_prefix = $order_by[0];
$order_by = $order_by[1];
}
$sql = 'SELECT p.*, product_shop.*, pl.* , m.`name` AS manufacturer_name, s.`name` AS supplier_name
FROM `'._DB_PREFIX_.'product` p
'.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` '.Shop::addSqlRestrictionOnLang('pl').')
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
LEFT JOIN `'._DB_PREFIX_.'supplier` s ON (s.`id_supplier` = p.`id_supplier`)'.
($id_category ? 'LEFT JOIN `'._DB_PREFIX_.'category_product` c ON (c.`id_product` = p.`id_product`)' : '').'
WHERE pl.`id_lang` = '.(int)$id_lang.
($id_category ? ' AND c.`id_category` = '.(int)$id_category : '').
($pdf ? ' AND p.`online_only` = 0' : '').
($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').
($only_active ? ' AND product_shop.`active` = 1' : '').'
ORDER BY '.(isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way).
($limit > 0 ? ' LIMIT '.(int)$start.','.(int)$limit : '');
$rq = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
if ($order_by == 'price')
Tools::orderbyPrice($rq, $order_way);
foreach ($rq as &$row)
$row = Product::getTaxesInformations($row);
return ($rq);
}
}
在你的代码中:
$productget = Product::getProducts(Context::getContext()->language->id, 0, 0, 'id_product', 'ASC', $osque, true, null, true);
为了避免缓存的麻烦,请考虑删除站点根目录下缓存文件夹中的文件class_index.php。
此致