Jump to content
Latest News: (loading..)
Nimmit

AJAX Attribute Manager support

Recommended Posts

Found that commenting out the code lines 415-430 for Product Attribute Code it goes away and all functions. I do not use Product Attribute Code so I do not know if commenting it out is correct or not but the error does go away. Wonder if I should comment it out elsewhere ?

Also picked up 3 missing semi-colons :

line 402 :  <?php echo AM_AJAX_IMAGE?>

line 436: <?php echo AM_AJAX_WEIGHT_PREFIX?>

line 439: <?php echo AM_AJAX_WEIGHT?>

Don't know if they affect anything...

 

Thank you again for your help !

Bobbee

Share this post


Link to post
Share on other sites

Hello @lucsangel,

I get an error:

Notice: Undefined index: code_suffix in C:\xampp_php_7_2\htdocs\2341-Frozen-QTPro\admin\attributeManager\classes\attributeManagerInstant.class.php on line 605

related to attributes code only if in attributeManagerConfigclass.php

the correspondant setting is switched to "true":

		$this->add('AM_USE_ATTRIBUTE_CODE' , true);

So if you do not use attributes code and don't have the correspondant add-on installed you have to keep this switched off instead to remove the code:

		$this->add('AM_USE_ATTRIBUTE_CODE' , false);

In general any additional add-on support setting should only be switched on if you have the correspondant add-on correct installed. Otherwise it's logic that you get error messages.

Share this post


Link to post
Share on other sites
16 minutes ago, raiwa said:

Hello @lucsangel,

I get an error:

Notice: Undefined index: code_suffix in C:\xampp_php_7_2\htdocs\2341-Frozen-QTPro\admin\attributeManager\classes\attributeManagerInstant.class.php on line 605

related to attributes code only if in attributeManagerConfigclass.php

the correspondant setting is switched to "true":


		$this->add('AM_USE_ATTRIBUTE_CODE' , true);

So if you do not use attributes code and don't have the correspondant add-on installed you have to keep this switched off instead to remove the code:


		$this->add('AM_USE_ATTRIBUTE_CODE' , false);

In general any additional add-on support setting should only be switched on if you have the correspondant add-on correct installed. Otherwise it's logic that you get error messages.

Hello Rainer,

It is switched off, never switched it on so why would the part of code in the function mentioned above throw the error? 

 

Bobbee

Share this post


Link to post
Share on other sites

Because you said that removing the related code eliminates the error and this code is only active if it is switched on.

I can't reproduce this error and I need the following to research it:

- a screenshot with the complete error message

- a zipped copy of your complete attributes manager files (admin/attributeManager/"all content")

Share this post


Link to post
Share on other sites

You made me think of something.... in attributeManagerConfig.class.php  I had AM_DELETE_ZERO_STOCK in the QTPro section set to true (as I had AM_USE_QT_PRO obviously set to true as I use it), now set it to false :

        $this->add('AM_DELETE_ZERO_STOCK', false); // if true, deletes options combinations with zero quantity from stock

and now the error is gone (with of course the changes you suggested line by line above). 

Just in case her are my zipped files

Thank you Rainer
 

attributeManager.zip

Share this post


Link to post
Share on other sites
6 minutes ago, lucsangel said:

You made me think of something.... in attributeManagerConfig.class.php  I had AM_DELETE_ZERO_STOCK in the QTPro section set to true (as I had AM_USE_QT_PRO obviously set to true as I use it), now set it to false :

        $this->add('AM_DELETE_ZERO_STOCK', false); // if true, deletes options combinations with zero quantity from stock

and now the error is gone (with of course the changes you suggested line by line above). 

Just in case her are my zipped files

Thank you Rainer
 

attributeManager.zip

Oh yes, in the zipped files the change to false is not shown as I zipped it before thinking of the QTPro stock deletion.

 

Sorry for all the trouble.

 

Bobbee

Share this post


Link to post
Share on other sites

I compared and tried your files. No difference to my files and I still can't reproduce the error.

The setting:

$this->add('AM_DELETE_ZERO_STOCK', true); // if true, deletes options combinations with zero quantity from stock

only activates the following query which can't produce the error you mention:

                       amDB::query("delete from products_stock where products_stock_id=$stock_id");

So the only possibility left is that you post a screenshot of your attributes manager window with the error message and all settings of the attributes and the product where the error appears.

 

Share this post


Link to post
Share on other sites

Rziner I do not have the error anymore. The image of the error was in one of my previous posts. For now all is well after setting that call to false.

Share this post


Link to post
Share on other sites

Uploaded update with the above posted fixes:

https://apps.oscommerce.com/mKsGy&ajax-attribute-manager-bs

AJAX Attribute Manager BS 2.9.3

+ Fixed undefined errors

+ Fixed PHP 7.2 warning errors.

 

Share this post


Link to post
Share on other sites

@raiwa Just an FYI.  This evening using Chrome, when going to a product to edit I was getting "unable to load URL" or something like that pop up window.  In the edit product page the attribute manager would not show. Access to stock was OK. I just could not work with attributes on this page.

No errors noted in the log.

I then uploaded the new update you provided today, and still got the same message and result.

I switched to Firefox and everything worked OK. 

So back in Chrome I cleared the cache in Chrome, and upon restart of that browser and going to edit a product, all worked..meaning attribute manager appeared again.

I'm not sure what the cause of that was, the only thing I was working on earlier this afternoon was adding attributes and I saved a new template I created in AM and was loading it onto a couple other products.  Which all worked, then I shut down and later upon attempting to pick up where I left off the above happened.

So anyway, just an FYI and mentioning for documentation in the event someone else has this happen.

Thx..SK

 


I am not a professional webmaster or PHP coder by background or training but I will try to help as best I can.

I remember what it was like when I first started with osC. It can be overwhelming.

However, I strongly recommend considering hiring a professional for extensive site modifications, site cleaning, etc.

There are several good pros here on osCommerce. Look around, you'll figure out who they are.

Share this post


Link to post
Share on other sites

A couple of minor issues:

  • Constant is defined twice in spanish:
Notice: Constant AM_AJAX_SORT already defined in attributeManager\languages\espanol\attributeManager.php on line 79 
  • When adding an option or restoring a template throws notices:
Notice: Undefined index: price in attributeManager\classes\attributeManager.class.php on line 370

Notice: Undefined index: prefix in attributeManager\classes\attributeManager.class.php on line 370

Notice: Undefined index: sortOrder in attributeManager\classes\attributeManager.class.php on line 370

Warning: Cannot modify header information - headers already sent by (output started at attributeManager\classes\attributeManager.class.php:370) in attributeManager\attributeManager.php on line 85

It only shows when error_reporting is set to all.

Share this post


Link to post
Share on other sites
On 11/12/2018 at 5:04 PM, raiwa said:

Gracias Juanma @piernas,

I'll have a look as soon as possible.

Can you also have a look why the contribution breaks if you set SESSION_FORCE_COOKIE_USE to True. It looks like the contribution can't find the session and is redirecting to admin/index.php.

'Force cookie usage' in the admin directory was introduced with oscommerce-2.3.4.

oscommerce-2.3.3.2 line 76 in catalog/admin/functions/sessions.php:

    if (isset($HTTP_GET_VARS[tep_session_name()])) {
      if (preg_match('/^[a-zA-Z0-9,-]+$/', $HTTP_GET_VARS[tep_session_name()]) == false) {

oscommerce-2.3.4 changed to:

    if ( isset($HTTP_GET_VARS[tep_session_name()]) ) {
      if ( (SESSION_FORCE_COOKIE_USE == 'True') || (preg_match('/^[a-zA-Z0-9,-]+$/', $HTTP_GET_VARS[tep_session_name()]) == false) ) {

If you remove (SESSION_FORCE_COOKIE_USE == 'True') || in the line above the contribution load as normal.

Share this post


Link to post
Share on other sites

Hello Juanma @piernas, hello Peter @petsk,

Sorry, there was an error in one file, please use this one.

I fixed all errors.

Can you please check and confirm. I'll then upload the new version.

Please replace all files (attributeManagerConfig.class has been modified, so please reconfigure if you have any add-on support switched on)

Note that support for Attribute Product Codes has been removed. It is very outdated and seems not to be mainained any more.

 

attributeManager.zip

Share this post


Link to post
Share on other sites

@raiwa warnings are still there. This fixes them:

in attributeManagerInstant-class.php

Change:

	function addAttributeToProduct($get) {
		
		$this->getAndPrepare('option_id', $get, $optionId);
		$this->getAndPrepare('option_value_id', $get, $optionValueId);
        $this->getAndPrepare('price', $get, $price);
		$this->getAndPrepare('prefix', $get, $prefix);
		$this->getAndPrepare('sortOrder', $get, $sortOrder);

to:

	function addAttributeToProduct($get) {
		
		$this->getAndPrepare('option_id', $get, $optionId);
		$this->getAndPrepare('option_value_id', $get, $optionValueId);
        // check if the variables are passed to the function:
        if (isset ($get['price'])) $this->getAndPrepare('price', $get, $price); 
		if (isset ($get['prefix'])) $this->getAndPrepare('prefix', $get, $prefix);
		if (isset ($get['sortOrder'])) $this->getAndPrepare('sortOrder', $get, $sortOrder);

 

Share this post


Link to post
Share on other sites

Hello Juanma @piernas,

I checked your fixes and I do not get any error messages without them.

I have also error reporting set to "all" and I'm running PHP 7.2

Are you sure that they are required. Did you replace/update all files with my new package.

Anyway, your fixes do not make any harm, but they should be applied also to the optional add-ons support.

My final function woul be this:

	function addAttributeToProduct($get) {
		
		$this->getAndPrepare('option_id', $get, $optionId);
		$this->getAndPrepare('option_value_id', $get, $optionValueId);
		if (isset($get['price'])) $this->getAndPrepare('price', $get, $price);
		if (isset($get['prefix'])) $this->getAndPrepare('prefix', $get, $prefix);

		if( (empty($price)) || ($price=='0') ) {
			$price='0.0000';
		} else {
			if ( (empty($prefix))||($prefix==' ') ){
				$prefix='+';
			}
		}
		if (empty($prefix)) {
			$prefix=' ';
		}

		$data = array(
			'products_id' => $this->intPID,
			'options_id' => $optionId,
			'options_values_id' => $optionValueId,
			'options_values_price' => $price,
			'price_prefix' => $prefix
		);

    if (AM_USE_MPW) {
      if (isset($get['weight'])) $this->getAndPrepare('weight', $get, $weight);
      if (isset($get['weight_prefix'])) $this->getAndPrepare('weight_prefix', $get, $weight_prefix);
    
      if ( (empty($weight)) || ($weight=='0') ) {
        $weight='0.0000';
      } else {
        if( (empty($weight_prefix))||($weight_prefix==' ') ) {
          $weight_prefix='+';
        }
      }
      if (empty($weight_prefix)) {
        $weight_prefix=' ';
      }
      
      $data['options_values_weight'] = $weight;
      $data['weight_prefix'] = $weight_prefix;
    }
    
// options images added by @raiwa 
    if (AM_USE_IMAGE) {
      if (isset($get['image'])) $this->getAndPrepare('image', $get, $image);
      if ( (empty($image)) || ($image=='0') ) {
        $image='';
      }
      $data['option_image'] = $image;
    }
		
    if (AM_USE_SORT_ORDER) {
      if (isset($get['sortOrder'])) $this->getAndPrepare('sortOrder', $get, $sortOrder);
			// changes by mytool
			// get highest sort order value
			$insertIndex = -1;
			$result = $this -> getSortedProductAttributes( AM_FIELD_OPTION_SORT_ORDER );
			// search for the current Sort Order where the new value needs to be added
			$i = -1;
			foreach($result as $key => $val) {
			  $i++;
   			if( $val['options_id'] == $optionId ){
   			  $insertIndex = $i;
        }
      }

			// if InsertIndex is still -1 then this is a new option and will be added at the end
			if($insertIndex > -1){
				$i = -1;
				$newArray = array();
				
				for ($n=0; $n < count($result) ; $n++){
					$i++;
   					if( $i == $insertIndex ){
 						$i++;
   						$data[AM_FIELD_OPTION_SORT_ORDER] = $i;
  						$newArray[$i] = $result[$n]; 
  					} else {
  						$result[$n][AM_FIELD_OPTION_SORT_ORDER] = $i; 
   						$newArray[$i] = $result[$n]; 
   					}
   				}
				
				$this->updateSortedProductArray($newArray);
				
			} else {
				$lastrow = end($result);
	   			$data[AM_FIELD_OPTION_SORT_ORDER] = (int)$lastrow[AM_FIELD_OPTION_SORT_ORDER] + 1;
			}
			// EO mytool
		}
		
		amDB::perform("products_attributes", $data);
	}

 

Thanks and best regards

Rainer

Share this post


Link to post
Share on other sites

Yes I made a blank install to test but making me doubt if every file was overwritten... I believe they were but I'll double-check. Anyway as you say this would not hurt.

Share this post


Link to post
Share on other sites

Uploaded update with the above posted fixes:

https://apps.oscommerce.com/mKsGy&ajax-attribute-manager-bs

AJAX Attribute Manager BS 2.9.4


+ Fixed undefined errors and other PHP  7.2 warning errors.
+ Removed support for attribute products code contribution.
+ Fixed incompatibility with admin => Configuration => Sessions => Force Cookie Use => true.

 

Share this post


Link to post
Share on other sites

Has anyone encountered the undefine offset error with addon?  Obviously, it only shows with E_ALL error reporting. 

( ! ) Notice: Undefined offset: 7 in C:\Apache24\htdocs\dfru\blah\attributeManager\classes\attributeManager.class.php on line 226

Call Stack

#

Time

Memory

Function

Location

1

0.2010

447352

{main}( )

...\attributeManager.php:0

2

0.3090

1983608

attributeManagerInstant->getAllProductOptionsAndValues( )

...\attributeManager.php:67

3

0.3090

1983656

attributeManager->getAllOptionsAndValues( )

...\attributeManagerInstant.class.php:467

 

( ! ) Notice: Undefined offset: 8 in C:\Apache24\htdocs\dfru\blah\attributeManager\classes\attributeManager.class.php on line 226

Call Stack

#

Time

Memory

Function

Location

1

0.2010

447352

{main}( )

...\attributeManager.php:0

2

0.3090

1983608

attributeManagerInstant->getAllProductOptionsAndValues( )

...\attributeManager.php:67

3

0.3090

1983656

attributeManager->getAllOptionsAndValues( )

...\attributeManagerInstant.class.php:467


I'm not really a dog.

Share this post


Link to post
Share on other sites

Actually, no I haven't fully updated it , but I found the problem.  It comes from attributeManagerInstant.class.php:467.  However, the problem is actually an anomaly in my database.  By adding the var_dump below after line 467 I found

  7 => 
    array (size=2)
      'name' => null

Instead of something like

  10 => 
    array (size=2)
      'name' => string 'Flocking' (length=8)

This is the dump I used to find this.

        var_dump($allOptionsAndValues);

So, the problem is in my database and I'll correct it.  Guess I should have thought aobut this more before posting, but I was brain farting it.  However, maybe my use of var_dump will give others ideas on solving. 

Edited by John W

I'm not really a dog.

Share this post


Link to post
Share on other sites

Funny thing, is this anomaly has existed for well over 10 years, and I didn't realize it.  I'm trying to take advantage of some slowing sales time to work on kinks and bugs that I've ignored for years.  I have to say that using Xdebug with Netbeans is pretty handy for things like this.  It creates a clickable link on my test site (local machine) that takes me to the line in Netbeans. 


I'm not really a dog.

Share this post


Link to post
Share on other sites

So, I've updated to 2.9.4 and testing it using E_ALL error reporting.  Got an undefined var warning when saving a product. 

On attributeManagerUpdateAtomic.inc.php line 27 I added the isset and it solved it.  Like below. 

if (isset(${AM_SESSION_VAR_NAME}) && is_array(${AM_SESSION_VAR_NAME}) && is_numeric($products_id)) {

I'll keep testing and report anything and I can find and hopefully offer a fix. 


I'm not really a dog.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×