VirtueMate to HikaShop switch. SOAP service?

  • Posts: 37
  • Thank you received: 1
10 years 2 months ago #172097

Hi,

we going switch from VirtueMate to HikaShop. One of task we see is about SOAP.

In VM was some support of SOAP, so we was able implement that
* our software application Valentina Studio, on first start show to user dialog asking for name/email,
* then send this to SOAP service, which was able create a new account in VM store and place a new order
* produce serial and send it back to app.

I have look around into docs and forum search, and I do not see anything about SOAP.
What is the best way to resolve this task with your shop?

Last edit: 10 years 2 months ago by ruslan_zasukhin.

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 2 months ago #172102

Hi,

The implementation of a WebService system into Hikashop is in our TODO list ; we are following the Joomla group, we want HikaShop to be compatible with the Joomla WebService system and for the moment, there is no real fixed specifications.
The system we want should be generic, in order to not only support "SOAP" as the web service protocol ; something more flexible.

As long as I know, SOAP in VM is made by a third party component.
And it is also possible to create a third party component for HikaShop in order to provide a SOAP interface for HikaShop features.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 37
  • Thank you received: 1
10 years 2 months ago #172196

Thank you.

1) So we should look on SOAP in the Joomla itself. First google brings me to this extension
extensions.joomla.org/extensions/miscell...us/development/21684

do you think this is correct way?

2) With VM what was good ... there was something working ...
I was able get some PHP file, and see code how to produce
new ps_order

* how to fill fields of that order and save it.
* how to check - if exists such account with such login and email ...

First of all I am going play now with that SOAP extension to make it responsive to our app, then I will need return back to question
HOW TO create account/order in HikaShop ? I need some API for this
HOW TO check existed accounts/orders to say yes/no to new login.

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 2 months ago #172262

Hi,

1) It talked about Web service in general.
Official doc : docs.joomla.org/Web_Services_Working_Group

The component you found is not the only one, you can found other, like techjoomla.com/rest-api-for-joomla
So for us it's difficult to choose a component, the two structure are different and the features are too.
That's why we want to be integrated with the WebService system in Joomla ; to be sure that it will be the common system that other component will use too.

2) HikaShop have a class organization.
If you want to create an account, there is the "user class", for the orders there is the "order class", etc.
The accounts in HikaShop can be linked with a Joomla account (if you want the account to have username+password), otherwise the account will be a "guest" account.

We have a developer documentation which could help you even if it is talking about the triggers more than the classes.
www.hikashop.com/support/support/documen...r-documentation.html

The best way to create an order is to create PHP object with the right variable and call the "save" function of the class order.
To get a sample of data, you can use the trigger "onBeforeOrderCreate(&$order,&$do)" to display the $order object. While making an order in the front end, you will have a good example of data.

In general, you can use the triggers in order to "dump" the values ; you will have a good idea of the data that you can provide to the classes' functions.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 37
  • Thank you received: 1
10 years 2 months ago #172790

Thank you for answers. I did some progress. I think I will explain Questions which have come to me, and how they was solved. To help other people. After that I will ask new questions which so far I cannot resolve. They will be in separate post.

Observation: we already have our C++ app, which jump to some URL where is located PHP file with SOAP service.
So we need have that file even with new shop.

STEP: I have open old php file, and have remove all code to get only 3 empty entry-points soap functions and one line which create SOAP server. Drop that file into required position /administrator/components/blablabla

STEP: 2 functions from that 3, just check if exists Login and email. I have play with return "1" or return "0", and all right, app see that.

STEP: I have decide implement these 2 functions, they was simple enough, just did SELECT to joe_users table to check existence of login or email. To make this working, I was need copy some first lines from PHP file of SOAP for VirtueMate. Thanks to that... Myself I never can guess such code. See it below. And I was need change only one line of code in existed funcs to get access to database.

So far I have the next PHP file.
Functions CheckUserLogin() and CheckUserEmail() work fine. But they even not touch HikaShop.
Now I need to make work function AddUser(), which in fact do 3 steps calling 3 sub-functions.
Yes the name AddUser() is bad, just historical glitch. Questions in the next msg.

<?php

define( '_VALID_MOS', 1 );
define( '_JEXEC', 1 );

ob_start();

$mosConfig_absolute_path= realpath( dirname(__FILE__).'/../../../..' );
require_once( $mosConfig_absolute_path.'/configuration.php' );

// init joomla cfg
//
define('JPATH_BASE', $mosConfig_absolute_path );
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

// for HikaShop:
require_once ( JPATH_BASE .DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php' );


// INITIALISE THE APPLICATION
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();



//****************************************************************************************
// Helper Methods:
//****************************************************************************************

	// -----------------------------------------
	function AddUserToJoomla( $params )
	{
		return 0;
	}
	
	// -----------------------------------------
	function CreateOrder( $user_id )
	{
		return 0;
	}

	// -----------------------------------------
	function UpdateOrderStatus( $new_order )
	{
		return 0;
	}
	
//****************************************************************************************
// SOAP entry points:
//****************************************************************************************

	// -----------------------------------------
	function AddUser($params) 
	{ 
		// Step 1: Add new user into Joomla
		$is_added = AddUserToJoomla( $params );
	
		if( $is_added )
		{
			// Step 2: Add new order with Valentina Studio product for 3 OS.
			//			This order belongs to just added new user.
			//
			$new_order = CreateOrder( /* $_REQUEST['user_id'] */ );
			if( $new_order > 0 )
			{
				// Step 3: Change the status of this order to Shiped to foce
				//	a) generation of serials
				// 	b) sending of Letter with serials to user.
				//
				$status_updated = UpdateOrderStatus( $new_order );
				if( $status_updated )
				{
					$res_str = "Success! Please check your mailbox. You should get 3 letters with serials for Mac OS X, Windows and Linux.";
				}
				else
				{
					$res_str = new SoapFault( "UpdateOrderStatusFault", "Cannot update OrderStatus  :" . $d['order_id'] );
				}
			}
			else // $new_order
			{
				$res_str = new SoapFault( "CreateOrderFault", "Cannot create order for user_id : " . $user_id );				
			}
		}
		else // $is_added
		{
			$res_str = new SoapFault( "JoomlaAddUserFault", "Cannot create user: " . $params->User->login );
		}
		
		// Return string about success OR error description.
		return $res_str;
	}



	// -----------------------------------------
	// CHECK if the given login of user exists in the table USERS of Joomla DB.
	// RETURNS "1" if exists, "0" - if not exists
	//
	function CheckUserLogin($params) { 
		$db = JFactory::getDBO();	

		$value=$params->login;
		$db->setQuery( "SELECT id FROM #__users WHERE username = '$value'" );
		$db->execute();
		
		return $db->getNumRows() > 0 ? "1" : "0";		
	}
	

	// -----------------------------------------
	// CHECK if the given email exists in the table USERS of Joomla DB.
	// RETURNS "1" if exists, "0" - if not exists
	//
	function CheckUserEmail($params) { 
		$db = JFactory::getDBO();	

		$value=$params->email;
		$q = "SELECT id FROM #__users WHERE email = '$value'";
		$db->execute();
		
		return $db->getNumRows() > 0 ? "1" : "0";		
	}
	
	 
//clean buffer
ob_end_clean();
	
	/* SOAP SETTINGS */
	$server = new SoapServer('VM_Users.wsdl');
	
	/* Add Functions */
	$server->addFunction( "AddUser" );
	$server->addFunction( "CheckUserLogin" );
	$server->addFunction( "CheckUserEmail" );

	$server->handle();
?> 

Last edit: 10 years 2 months ago by ruslan_zasukhin.

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

  • Posts: 37
  • Thank you received: 1
10 years 2 months ago #172794

QUESTION: How to add user into both Joomla and Shop?

You did answer I have to use classes. Okay I have learn classes and code, but I do not see easy way todo this.
This is how it was in code with VM:

function AddUser2($params) {
	
		include('../vm_soa_conf.php');
		
		$ps_user = new ps_user();
		
		$_SESSION["ps_vendor_id"] = "1";
		$_SESSION["auth"]		  = "admin";

		$user['username']   = $params->User->login;
		$user['email']      = $params->User->email;
		$user['password']   = $params->User->password;
		$user['password2']  = $params->User->password;
		$user['first_name'] = $params->User->firstname;
		$user['last_name']  = $params->User->lastname;

		$_POST['email']	    = $user['email'];
		$_POST['usertype']	= "Registered";
		$_POST['agreed']	= "1";
		$_POST['block']	    = "0";
		$_POST['sendEmail']	= "0";
		$_POST['username']  = $user['username'];
		$_POST['name']      = $user['username'];
		$_POST['password']  = $user['password'];
		$_POST['password2'] = $user['password'];
		$_POST['gid'] 		= "18"; //registred
		
		// CALL to VM STORE:
		$is_added = $ps_user->add($user);
		
		// RETURN:
		return $is_added;
}

All I was able discover myself is
function AddUserToJoomla( $params )
{
	$userClass = hikashop_get('class.user');

	return 0;
}

I see in this class some register() function, but I do not see how I can pass parameters ?

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 2 months ago #172894

Hi,

You need to create the user in Joomla first, using the Joomla API/functions.
Then you will be able to use the "save" function of the HikaShop user class, giving him an object with the fields you want to store in the database.
You can check the table "hikashop_user" to know more about the different fields you can save in the database.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 37
  • Thank you received: 1
10 years 2 months ago #173046

Jerome wrote: You need to create the user in Joomla first, using the Joomla API/functions.
Then you will be able to use the "save" function of the HikaShop user class, giving him an object with the fields you want to store in the database.
You can check the table "hikashop_user" to know more about the different fields you can save in the database.


Thank you, but not very clear yet.

1) Using Joomla API I need create only object User? like in this function with new StdClass?
function getID($cms_id,$type='cms'){
		$user = $this->get($cms_id,$type);
		$id = (int)@$user->user_id;

		if(empty($id)&&$type=='cms'){
			$userData = JFactory::getUser($cms_id);
			if(!empty($userData)){
				$user = new stdClass();
				$user->user_cms_id = $cms_id;
				$user->user_email = $userData->email;
				$id = $this->save($user);
			}

		}

		return $id;
	}

Or I need also create it in DB in table jos3_users?

2) BTW, do you think this function getID() should be used in my case?
It seems it "converts" cmd_id user into HikaShop user object


3) Yes I already have learned all DB Schema of course.
And I afraid I need yet save e.g. Company, which is located in table Address ?
So in some way, I need touch 3 tables via Joomla API + HikaShop API
jos3_users
jos3_hikashop_user
jos3_hikashop_address

may be even more tables.

Do you think in HikaShop code exists any place or example where such job is done?
I did search by the whole folder of HikaShop sources ... its hard to find such place for me.

So far I am keep reading ... I have read user.save() function.
I see that your functions tend to be quite "fat", i.e. when one function do a lots of actions...
It seems it is implemented some kind of Object-to-DB logic ... like in ORMs.

save() function can save as new object, so update existed one, I guess it can recognize any changed property to save it...

Last edit: 10 years 2 months ago by ruslan_zasukhin.

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 2 months ago #173127

Hi,

To create a Joomla user using code, please see:
docs.joomla.org/
Or
forum.joomla.org/

The getID function is just a function to load a Joomla user, there is no link with the user creation in Joomla.

3/ Yes, you might also need to save an address for the created user ; using the HikaShop address class with the same kind of working : the "save" function.

I understand that it can be complicated to browse all HikaShop code, there are now a lot of files.
But the classes (in the administrator/components/com_hikashop/classes/ folder) are here to help. You can create new entries or update current entries thanks to that classes.

And yes, that's an ORM logic, like in Joomla itself. We are using the same coding way.
You just have to give an object to the function with the data you want to save, the "save" function will do his job and will call the different triggers (in order to be compatible with the rest of plugins/components).

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 37
  • Thank you received: 1
10 years 1 month ago #173600

Jerome wrote: You need to create the user in Joomla first, using the Joomla API/functions.
Then you will be able to use the "save" function of the HikaShop user class, giving him an object with the fields you want to store in the database.
You can check the table "hikashop_user" to know more about the different fields you can save in the database.


Hi Jerome,

Okay, finally I have got pice of code, which is able create user in Joomla from external script called via SOAP. GOOD.
So I have $user_cms_id

I have spend now again about 60 minutes, reading user.php of HikaShop, as well as others.
And may be I am totally stupid, but I cannot understand how to step from Joomla user to instance of HikaShop user.

Let me explain why I have problems here and where my brain is lost. You can read only if you are interested to see this lost-walks. Question itself is at the end.

1) HOW TO CREATE INSTANCE of hikashopUserClass?

1.1) Create instance via new?
  new hikashopUserClass ?

1.2) But in many places of HikaShop I see line as:
$userClass = hikashop_get('class.user');


2) HOW TO bind this instance of hikashop user to user_cms_id?

Again I see different places about this, but they are different. For example:

2.1) field.php:
$userClass = hikashop_get('class.user');
$user = $userClass->get($user_id);
$guest = !(bool)@$user->user_cms_id;

2.2) classes/user.php

For me this function looks like perfect factory-convertor cms_id into hikashop user instance.
But you say NO, not for me.
function getID($cms_id,$type='cms'){
		$user = $this->get($cms_id,$type);
		$id = (int)@$user->user_id;

		if(empty($id)&&$type=='cms'){
			$userData = JFactory::getUser($cms_id);
			if(!empty($userData)){
				$user = new stdClass();
				$user->user_cms_id = $cms_id;
				$user->user_email = $userData->email;
				$id = $this->save($user);
			}

		}

		return $id;
	}


2.3) classes/user.php

Function SAVE() is absolutely confusing after even 5 times reading. Why? It is enough to look on first lines
	function save(&$element,$skipJoomla=false){
		$new = true;
		if(!empty($element->user_id)){
			$new = false;
		}else{
			if(empty($element->user_created_ip)){
				$element->user_created_ip = hikashop_getIP();
			}
			if(empty($element->user_created)){
				$element->user_created = time();
			}
			if(empty($element->user_email)&&!empty($element->user_cms_id)){
				$user = JFactory::getUser($element->user_cms_id);
				$element->user_email = $user->email;
			}elseif(!empty($element->user_email)&&empty($element->user_cms_id)){
			}
		}

** IF something is empty it is able to use user_cms_id from $element, which comes as EXTERNAL parameter.

Question comes to mind: Hmmm, may be I should here pass my cmd_id? But what is $element in this case?

** Okay, I try to find call of this save() method, to see what is $element ... and I find such call in the same user.php
function saveForm(){
...
		$element = $fieldsClass->getInput('user',$oldUser);
...
		$element->user_id = $user_id;
		$status = $this->save($element);
...

and
function register(&$checkout,$page='checkout',$redirect=true){
...
		$userData = $fieldClass->getInput('user',$old,!@$checkout->cart_update);
...
				$this->user_id = $this->save($userData);
...

So here I see that $element in save() in fact is some $userData, which comes from getInput()....
what is this? how to use this? Again Puzzle...
Besides I do not need any Input() ...

==============================================================================
Jerome, this is why without docs and comments in code, just reading CODE, it is far not enough to GUESS how to use that classes and methods. And be sure, I am very used to quite complex projects.

You see? Will be great to get few more samples, comment over each class and over most important methods which users can use.

I perfectly understand that your product works well, and you can use it, but we must be able also :)

Okay, finally can you provide that few lines code to give me push forward?

My current state is below.
I need some push to start work with AddUserToHikaShop()
Thank you for any help here :)
	function AddUserToJoomla( $params )
	{
		$user = new JUser;

		// RZ: if you look into code of bind() function, you will see it cares first of all
		// about username and passwords, making hash of password also.
		// So these 3 params we assign to using via bind(), all rest params via set() methods.
		//
		$data = array( 
			'username' => $params->User->login,
			'password' => $params->User->password,
			'password2'=> $params->User->password,
		);

		$bind_res = $user->bind($data);

		$user->set( 'name'		, $params->User->firstname.' '.$params->User->lastname );
		$user->set( 'email'		, $params->User->email );
		$user->set( 'block'		, 0 );
		$user->set( 'groups'	, array("2")  );
			
		if(	$user->save() )
			return $user->id;
		else
			return false;
	}

	function AddUserToHikaShop( $params, $cms_user_id )
	{
//		$userClass = hikashop_get('class.user');

                ????????????????????????????????????????????????????????????????????????????????
	}
	
//****************************************************************************************
// SOAP entry points:
//****************************************************************************************

	// -----------------------------------------
	function AddUser($params) 
	{ 
		// Step 1: Add new user into Joomla
		$cms_user_id = AddUserToJoomla( $params );
		if( $cms_user_id == false )
			return new SoapFault( "AddUserToJoomlaFault", "Cannot create user: " . $params->User->login );

                // Step 2: Add new user to HikaShop
               $hika_user_id = AddUserToHikaShop(  $cms_user_id );

Last edit: 10 years 1 month ago by ruslan_zasukhin.

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 1 month ago #173633

Hi,

1 - Create an instance of hikashopUserClass
You have to use the code that HikaShop use.

$userClass = hikashop_get('class.user');
Because you can't know if the HikaShop user class file as been included or not.
But you won't get an "instance" like you think you would.

2 - How to bind this instance of hikashop user to user_cms_id
You don't have to, it's not the HikaShop logical.
The user class is like the "model" in a MVC structure ; the class is a generic class with function but you don't have to create several classes for different "instances". There is no "instance", there is the class and the data.

That's why in the "save" function you have to give the "$element" variable which is the data.
The function "get" will give you the existing data from the database and you have to work with the data, and use the class to perform specific actions.

And the "save" of the HikaShop user class will fill some data in the variable $element only if you want to add a new element in the database.
If the "user_id" is empty you will create a new entry in the database ; otherwise you will update an existing one.
So the function "save", when you create a new element, simply the code by filling some data if not present.

Joomla have a "bind" data which convert an array to an object ; in HikaShop we just deal with an object.

HikaShop have been more design to work with plugins than other kind of integration ; that's why the developer documentation does not explain the core classes, it just talk about the plugins.
I understand that for some cases like yours, it's not a good thing and I understand that it's not easy to grasp like that.

I'm a third party developer who finally developed two big add-on for HikaShop ; so I had to study HikaShop and asked Nicolas about the code too.

But like I told you in previous post, dealing with the HikaShop classes is not complicated at all.
You just need to give the data, the $element variable which is a stdClass with the content.
$userClass = hikashop_get('class.user');
$user = new stdClass();
$user->user_cms_id = $cms_user_id;
$user->user_email = $params->User->email;
$ret = $userClass->save($user);
if(!empty($ret))
  $user->user_id = $ret;

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Last edit: 10 years 1 month ago by Jerome.
The following user(s) said Thank You: ruslan_zasukhin

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

  • Posts: 37
  • Thank you received: 1
10 years 2 weeks ago #178652

Hi Jerome,

and now I have return to this SOAP task ...
I was able to write the next function to create order with 3 variants of our free product.
Variants are just for mac, linux and windows versions.

function CreateOrder( $user_id )
{
// PRODUCTs prepare:

	$productClass = hikashop_get('class.product');

	$product_vstd_lin = $productClass->get( 173 ); 		// VSTD-LIN-NEW
	$product_vstd_lin->order_product_quantity = 1;

	$product_vstd_win = $productClass->get( 175 ); 		// VSTD-MAC-NEW
	$product_vstd_win->order_product_quantity = 1;

	$product_vstd_mac = $productClass->get( 177 ); 	// VSTD-WIN-NEW
	$product_vstd_mac->order_product_quantity = 1;

// ORDER:
	$order = new stdClass();

	$order->order_user_id = $user_id;
	$order->cart = new stdClass();
	//
	$order->cart->products 		= array( $product_vstd_lin );
	$order->cart->products[] 	= $product_vstd_win;
	$order->cart->products[] 	= $product_vstd_mac;

// SAVE:	
	$orderClass = hikashop_get('class.order');
	$order->order_id = $orderClass->save( $order );
	error_log( "CreateOrder: saved with order_id = $order->order_id" );

	return $order;
}

** Order is created in DB:
- one record in the table Orders;
- 3 child-records in the table Order_Products;

And email arrives that "new order was created on your site". GOOD

PROBLEM

is only that these 3 records about product_orders have empty fields for Product_Name and Product_Code... And in the email there is no names of products, only quantity and price 0.00.

* Product_Code is not hard to fill in my code...
* But Product_Name ... I wonder if this is right way? Why I should repeat in PHP code values already stored in Products table?

I was in hope that
$productClass->get( 175 );

will load data-fields for that product, but it seems nothing like this.

So what is correct way ?

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

  • Posts: 37
  • Thank you received: 1
10 years 2 weeks ago #178729

Well, after filling in code most of properties, I have got it almost working.

I get letter to ADMIN --- New order was created.

GOOD - order is automatically change status to Confirmed, because price = 0
GOOD - In this letter now present serials ...

PROBLEM -- there is no letter to user.
May be I need to set some property 'send to user' ?

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 2 weeks ago #178708

Hi,

A product is not an order_product.
If you look at the tables "product" and "order_product" you will see that they have different columns and names for their columns.

In the order you put "order_product", which can make a reference to a "product_id" but not always.
there is no "product_code" or "product_name", there is a "order_product_code" and a "order_product_name".

So you need to put order products in the order cart, so they will be correctly saved in the database.
You can still do a productclass->get to get the product name and code ; but you can't give the entire product object ; because it's not an order_product object.

For the user notification, you need to set

$order->history = new stdClass();
$order->history->history_notified = true;

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Last edit: 10 years 2 weeks ago by Jerome.

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

  • Posts: 37
  • Thank you received: 1
10 years 2 weeks ago #178826

BUG?

* before I will ask other questions about SOAP, I want discuss strange warning/error and code, which looks as bug for me.
* this problem happens just in HikaShop, not touching SOAP...
If this is early bug - I think we can copy paste this to other branch of forum.

So description.

We have product and few variants of it. Product is FREE.
I place order as user, all is right, 3 letters comes, serials fine.

PROBLEM is that in error_log I see such messages:

[08-Nov-2014 20:56:27 Europe/Berlin] PHP Notice:  Undefined offset: 175 in /Applications/MAMP/htdocs/valentina-db.net/media/com_hikashop/mail/order_status_notification.preload.php on line 116

if look into code I see the following important lines:
$products_ids = array();
foreach($data->cart->products as $item) { $products_ids[] = $item->product_id; }
...
$productClass->getProducts($products_ids);
...
	$product = $productClass->products[$item->product_id];   <<<<<<<<<< here error

In our case product_id is 175.
So this line tries to get 175th element of array ???

I have dumped arrays and see that they are
[08-Nov-2014 20:56:27 Europe/Berlin] order_status_notification_preload.php -- products_ids
[08-Nov-2014 20:56:27 Europe/Berlin] array(1) {
  [0]=>
  string(3) "175"
}

[08-Nov-2014 20:56:27 Europe/Berlin] order_status_notification_preload.php -- products
[08-Nov-2014 20:56:27 Europe/Berlin] array(0) {
}


* So products array is EMPTY ?!

* Also by logic of code ... it seems ... we take some set of product_ids from the Cart ... e.g. 1-3 items in Cart.
* then we get products using this set
* so we have array $productClass->products with products only for this set?
in my case it is even empty ...

So how we can try get products[175] ?
OF course ERROR: offset is not found ...

Last edit: 10 years 2 weeks ago by ruslan_zasukhin.

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 2 weeks ago #178835

Hi,

The warning is just a miss.
If you look at the email "order_creation_notification.preload" or "order_admin_notification.preload" you will see the line

$product = @$productClass->all_products[$item->product_id];
I fixed the email in our side so the warning will be avoid.

But you got the warning because you created an order with a product which does not exist or not available.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 37
  • Thank you received: 1
10 years 2 weeks ago #178884

Jerome wrote: Hi,

The warning is just a miss.
If you look at the email "order_creation_notification.preload" or "order_admin_notification.preload" you will see the line

$product = @$productClass->all_products[$item->product_id];
I fixed the email in our side so the warning will be avoid.


Do you mean that you have fixed some code?
Do you mean that in file order_status_notification.preload.php also should be
$product = $productClass->all_products[$item->product_id];
instead of
$product = $productClass->products[$item->product_id];
?

Well, I have try such "fix" and really THIS warning go away. BTW, I am working with HikaShop 2.3.2


Jerome wrote: Hi,
But you got the warning because you created an order with a product which does not exist or not available.


No no no.

product EXISTs of course.
I can see it in backend and fronted of shop.
I can choose and put it into Cart.
I get letter which correctly lists this product.
and even serials are generated.
All right here.
And I can see it in DB tables also :)


Again, I get this warning without any SOAP.
I get it only working in fronted of shop choosing free product into cart, and then checkout order. With 0.00 price.

Last edit: 10 years 2 weeks ago by ruslan_zasukhin.

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 2 weeks ago #178992

Hi,

Okay ; that is strange so.
I can't reproduce it with the fix.

We will require more details about the product ; because the function getProducts from the product class should load it and let it available in the array "all_products".

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 37
  • Thank you received: 1
10 years 2 weeks ago #179008

Jerome wrote: Hi,
Okay ; that is strange so.
I can't reproduce it with the fix.

We will require more details about the product ; because the function getProducts from the product class should load it and let it available in the array "all_products".


Hi Jerome,

but in file order_status_notification.preload.php
line looks as
$product = $productClass->products[$item->product_id];  
                          ^^^^^^^^^^^ 

Here is used array products[],
but not all_products[]

at least in HikaShop 2.3.2, which is installed on my machine.
When I have change to all_products[], warning go away ...

Although I still see some 2-3 strange notifications. Going to discuss them later.

Last edit: 10 years 2 weeks ago by ruslan_zasukhin.

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

Time to create page: 0.096 seconds
Powered by Kunena Forum