Well the situation is that:
I have an webservice that return data to me.
If I use a function "print_r" I can see all array coming from this webservice.
After that i have maked an plugin with this function:
<?php
defined('_JEXEC') or die('Restricted access');
require_once (JPATH_SITE.'/templates/xxxxx/includes/webserviceCall.php');
class plgChangedPrice extends JPlugin
{
function plgChangedPrice(&$subject, $config)
{
parent::__construct($subject, $config);
$this->reportError = new treatErrors;
if(!isset($this->params))
{
$plugin = JPluginHelper::getPlugin('hikashop', 'history');
jimport('joomla.html.parameter');
if(version_compare(JVERSION,'2.5','<'))
{
$this->params = new JParameter($plugin->params);
}
else
{
$this->params = new JRegistry($plugin->params);
}
}
}
function onHikashopBeforeDisplayView(&$view)
{
$pIncludeScales = true;
$price = new stdClass;
$sess = JFactory::getSession();
$price->price_currency_id = hikashop_getCurrency();
$price->price_min_quantity = 1;
if($view->getName() == 'product' && !$sess->get('user')->guest)
{
if($view->getLayout() == 'show')
{
$view->element->product_code = strrpos($view->element->product_code, '-') > 0 ? substr($view->element->product_code, strrpos($view->element->product_code, '-')+1, strlen($view->element->product_code)) : $view->element->product_code;
$prodCode = new cPriceListProductInput($view->element->product_code, $view->element->product_min_per_order);
$pProductList[] = $prodCode;
}
else
{
foreach ($view->rows as $key => $val)
{
$view->rows[$key]->product_code = strrpos($val->product_code, '-') > 0 ? substr($val->product_code, strrpos($val->product_code, '-')+1, strlen($val->product_code)) : $val->product_code;
$prodCode = new cPriceListProductInput($view->rows[$key]->product_code, $val->product_min_per_order);
$pProductList[] = $prodCode;
}
}
$this->reportError->postError();
if(!$sess->get('user')->guest && $sess->has('userINAInfo'))
{
$user = $sess->get('userINAInfo');
$iWS = new cInapaws;
$iPL = $iWS->ProductPriceList($user['customers_ISIAccount'], $pIncludeScales, $pProductList);
$iCA = $iWS->CheckAvailability($user['customers_ISIAccount'], $user['entry_postcode'], $prodCode->id, $prodCode->qtd);
if($view->getLayout() == 'show')
{
if(empty($view->element->prices))
{
$view->element->prices = array($price);
}
if($iPL[0]->WebPrice > 0)
{
$view->element->price_value = $iPLt[0]->WebPrice;
foreach($view->element->prices as $k => $garbage)
{
$view->element->prices[$k]->price_value = $iPL[0]->WebPrice;
$view->element->prices[$k]->price_value_with_tax = $iPL[0]->WebPrice;
$view->element->amount = $iPL[0]->WebPrice;
}
}
$view->element->product_quantity = $iCA[0]->Warehouse[0]->Expedition.'h';
}
else
{
if(count($view->rows) > 0)
{
foreach($iPL as $keyW=>$wsVal)
{
foreach($view->rows as $keyP=>$prodVal)
{
if($view->rows[$keyP]->product_code == $iPL[$keyW]->id)
{
if($wsVal->WebPrice != 0)
{
if(empty($view->rows[$keyP]->prices))
{
$view->rows[$keyP]->prices = array($price);
}
$view->rows[$keyP]->price_value = $wsVal->WebPrice;
foreach($view->rows[$keyP]->prices as $k => $garbage)
{
$view->rows[$keyP]->prices[$k]->price_value = $wsVal->WebPrice;
$view->rows[$keyP]->prices[$k]->price_value_with_tax = $wsVal->WebPrice;
$view->rows[$keyP]->amount = $iPL[0]->WebPrice;
}
}
}
unset($price);
$price = new stdClass;
$price->price_currency_id = hikashop_getCurrency();
$price->price_min_quantity = 1;
}
}
}
}
}
$this->reportError->postError();
}
}
?>
Now what i need is:
If the webservice return amount value this plugin will automatic change the product price. If the amount return empty the product price will be the original in DataBase.
With this plugin when I see the product, the price is currently changed but when i added to cart the price in cart isn't from webservice but from database and the same append with the TOTAL PRICE because this calculate with the price returned from the database and not from the webservice.
I have created a field in hikashop called amount and if i put this ON in front end view everything works great but i can't show this field, so when i turn off the frontend view, this stopped to work.
So what i want is, can you help me to change this value without necessary to put the fields on in frontend view?