News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Question for a moded virtuemart

Started by skid648, July 28, 2016, 09:16:33 AM

Previous topic - Next topic

skid648

Hello ,
Let me apologize if i ask too muh but i would love another thought.
I have a virtuemart with some custom code ont it for shoppergroup assignment with geolocation!
I also have custom filters pro , and everything is working ok except sorting product by price.

I have modded public_html\administrator\components\com_virtuemart\models\product.php

with this line :



function GetShopper($currentVMuser,$virtuemart_shoppergroup_ids){

$isGuest = $currentVMuser->JUser->guest; // 1 if he is

if($isGuest === 1){

/* logic for my geolocation */

if(strcmp($country_code, "GR") !== 0){

$virtuemart_shoppergroup_ids[0] = 3;

}else{

$virtuemart_shoppergroup_ids[0] = 4;
}

}

return $virtuemart_shoppergroup_ids;


}





if($virtuemart_shoppergroup_ids===0){

$usermodel = VmModel::getModel ('user');
$currentVMuser = $usermodel->getCurrentUser ();
if(!is_array($currentVMuser->shopper_groups)){
$virtuemart_shoppergroup_ids = (array)$currentVMuser->shopper_groups;
} else {
$virtuemart_shoppergroup_ids = $currentVMuser->shopper_groups;
}
$virtuemart_shoppergroup_ids = GetShopper($currentVMuser,$virtuemart_shoppergroup_ids);

}




and  public_html\components\com_customfilters\models\products.php

with this line:


if($prices_per_shopper){

$usermodel = VmModel::getModel ('user');

$currentVMuser = $usermodel->getUser();

$virtuemart_shoppergroup_ids = cftools::getUserShopperGroups();
       
        /* logic for geolocation */

if(strcmp($country_code, "GR") !== 0){

$virtuemart_shoppergroup_ids[0] = 3;

JArrayHelper::toInteger($virtuemart_shoppergroup_ids);

if(!empty($virtuemart_shoppergroup_ids)  && is_array($virtuemart_shoppergroup_ids))

$whereShopper = 'pp.`virtuemart_shoppergroup_id` IN('.implode(',', $virtuemart_shoppergroup_ids).')';
$where[] .= $whereShopper;
//prices for all shopppers

}else{

$virtuemart_shoppergroup_ids[0] = 4;

JArrayHelper::toInteger($virtuemart_shoppergroup_ids);

if(!empty($virtuemart_shoppergroup_ids)  && is_array($virtuemart_shoppergroup_ids))

$whereShopper = 'pp.`virtuemart_shoppergroup_id` IN('.implode(',', $virtuemart_shoppergroup_ids).')';
$where[] .= $whereShopper;
//prices for all shopppers

}


}


I am trying 3 days now to fix this, but cant get why this is happening!
Debuging product sorting i found that the query that runs to sort the products is this :



SELECT SQL_CALC_FOUND_ROWS p.`virtuemart_product_id` , IF( pp.override, pp.product_override_price, pp.product_price ) AS product_price
FROM  `t1nth_virtuemart_products` AS p
LEFT JOIN  `t1nth_virtuemart_product_shoppergroups` AS ps ON p.`virtuemart_product_id` =  `ps`.`virtuemart_product_id`
LEFT JOIN  `t1nth_virtuemart_product_categories` AS pc ON p.`virtuemart_product_id` =  `pc`.`virtuemart_product_id`
LEFT JOIN  `t1nth_virtuemart_product_prices` AS pp ON p.`virtuemart_product_id` = pp.`virtuemart_product_id`
WHERE (
`pc`.`virtuemart_category_id` =2
AND (
`ps`.`virtuemart_shoppergroup_id` =  "4"
OR  `ps`.`virtuemart_shoppergroup_id` IS NULL
)
AND p.`published` =  "1"
)
GROUP BY p.`virtuemart_product_id`
ORDER BY  `product_price` ASC ,  `virtuemart_product_id` ASC



and it bassically ignores this condition


`ps`.`virtuemart_shoppergroup_id` =  "4"


resulting to sort product by prices on some other shoppergroup!


Let me know if you have any idea on what is maybe wrong, thank you!


Template: JV-marvel
Virtuemart: VirtueMart 3.0.12
Joomla: 3.5.1










Milbo

You make it quite hard for your self. There are cheap geolocator plugins, no need to invent the wheel again.  and if you mod it, you must write this as plugin. Changing the vm core is not a good idea.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

skid648

Oh thanks a lot, i accidentally ripped the scratcher and i solved it. 8)