HELP with unit_price of the product

  • Posts: 57
  • Thank you received: 4
9 years 11 months ago #181105

-- HikaShop version -- : 2.3.4
-- Joomla version -- : 3.3.6
-- PHP version -- : 5.5.9
-- Error-message(debug-mod must be tuned on) -- : Problem to set variable of product unit_price and show in all views of this shop.

Hi guys,

I need your help.
I have a webservice to get a price from our seller internal program and place in a website.
I have created a field called amount and activated the donate plugin.

The customers have different prices so, my webservice send the product_code, the quantity and the user_id, and the webservice return a price for this product.

The problem start here.
I can see the price comming from webservice in a webpage, but what i need to do to set temporary the unit_price in this product for that product stay with him since the begining of the webservice call at the end and saved in a DB order/invoice with this price given from the webservice?

Thanks for you help.

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
9 years 11 months ago #181125

Hello,

I can see the price comming from webservice in a webpage, but what i need to do to set temporary the unit_price in this product for that product stay with him since the begining of the webservice call at the end and saved in a DB order/invoice with this price given from the webservice?

I didn't totally understood your issue, can you give us more information about your webservice for example, so that we can help you with it ?

Please Log in or Create an account to join the conversation.

  • Posts: 57
  • Thank you received: 4
9 years 11 months ago #181283

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?

Please Log in or Create an account to join the conversation.

  • Posts: 82726
  • Thank you received: 13342
  • MODERATOR
9 years 11 months ago #181290

In that case you can implement the onAfterCartProductsLoad trigger in order to modify the prices of the products during the loading of the cart.

The following user(s) said Thank You: rfernandes

Please Log in or Create an account to join the conversation.

  • Posts: 57
  • Thank you received: 4
9 years 11 months ago #181446

I can see in your documentation that you have a lot of functions like that.
Can you display a small summary each one?

I'm sorry to disturbe, but i really need to understand your documentation to implement our system in your business component.
Thanks.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
9 years 11 months ago #181449

Hi,

Have you read that documentation:
www.hikashop.com/support/support/documen...umentation.html#cart

All the triggers are present in this list, and are detailed.

Please Log in or Create an account to join the conversation.

Time to create page: 0.083 seconds
Powered by Kunena Forum