Page 1 of 2 12 LastLast
Results 1 to 10 of 20
  1. #1
    Join Date
    Mar 2005
    Posts
    229
    Plugin Contributions
    0

    Default Notifier question

    Hello,

    I'm in the process of upgrading an 1.5.0 to 1.5.4, it's quite difficult cause I have a bunch of modules installed (Edit Orders, Super Orders, Encrypted Master Password,...) and even a custom module.

    I'm getting an error in /includes/classes/order.php that I managed to solve by changing a line :
    I replaced
    $this->notify('NOTIFY_ORDER_CART_FINISHED', &$this);
    by
    $this->notify('NOTIFY_ORDER_CART_FINISHED');

    Ok, it works now but I'm wondering if, by doing so, I'm not breaking something else or even, not breaking something today but tomorrow, with updates...

    What are the risks of modifying the line the way I did ?

    Thanks for your advices

    Regards

    Hubert

  2. #2
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: Notifier question

    Quote Originally Posted by hubert View Post
    Hello,

    I'm in the process of upgrading an 1.5.0 to 1.5.4, it's quite difficult cause I have a bunch of modules installed (Edit Orders, Super Orders, Encrypted Master Password,...) and even a custom module.

    I'm getting an error in /includes/classes/order.php that I managed to solve by changing a line :
    I replaced
    $this->notify('NOTIFY_ORDER_CART_FINISHED', &$this);
    by
    $this->notify('NOTIFY_ORDER_CART_FINISHED');

    Ok, it works now but I'm wondering if, by doing so, I'm not breaking something else or even, not breaking something today but tomorrow, with updates...

    What are the risks of modifying the line the way I did ?

    Thanks for your advices

    Regards

    Hubert
    Normally, $this->notify('NOTIFY_ORDER_CART_FINISHED', &$this); would be written as: $this->notify('NOTIFY_ORDER_CART_FINISHED', $this); if anything were carried over as part of the notifier, but someone very well could have written the array portion of the notifier system to work like the newer method that directly takes advantage of passing a variable to allow it to be editable.

    The real question since it seems that the new code that has been edited is where did that code come from, how was it to use that notifier, and what affect does removal have on it? If not mistaken, there is no need to pass the $this variable because it is already assigned to the first variable within the "observer" system.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,474
    Plugin Contributions
    88

    Default Re: Notifier question

    Quote Originally Posted by hubert View Post
    Hello,

    I'm in the process of upgrading an 1.5.0 to 1.5.4, it's quite difficult cause I have a bunch of modules installed (Edit Orders, Super Orders, Encrypted Master Password,...) and even a custom module.

    I'm getting an error in /includes/classes/order.php that I managed to solve by changing a line :
    I replaced
    $this->notify('NOTIFY_ORDER_CART_FINISHED', &$this);
    by
    $this->notify('NOTIFY_ORDER_CART_FINISHED');

    Ok, it works now but I'm wondering if, by doing so, I'm not breaking something else or even, not breaking something today but tomorrow, with updates...

    What are the risks of modifying the line the way I did ?

    Thanks for your advices

    Regards

    Hubert
    You're most likely receiving an error on that line (the actual error message would have helped!) due to later PHP versions (5.3 and later, if memory serves) no longer allowing the specification of an object's reference by a function caller; that reference must be specified on the function's definition.

    That aside, in removing that offending parameter specification, you've restored the notifier to it's "as shipped" Zen Cart v1.5.4 version. As mc12345678 indicated, the order-class data can be accessed by the catching observer's use of the $class parameter. You just need to find the observer-class element that's expecting to see that information as a notification parameter (since it's no longer there)!

  4. #4
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: Notifier question

    Quote Originally Posted by hubert View Post
    I'm getting an error in /includes/classes/order.php that I managed to solve by changing a line :
    I replaced
    $this->notify('NOTIFY_ORDER_CART_FINISHED', &$this);
    by
    $this->notify('NOTIFY_ORDER_CART_FINISHED');

    Ok, it works now but I'm wondering if, by doing so, I'm not breaking something else or even, not breaking something today but tomorrow, with updates...

    What are the risks of modifying the line the way I did ?

    Thanks for your advices
    I'm guessing that the error message was:
    "call-time pass-by-reference" is deprecated

    Basically this means that the code is old/obsolete

    Your fix/change is probably not going to cause any problems (in this instance) either now or in the future, but a bigger worry is that since this is old code and you've just updated to v1.5.4 how did it get missed, and what other files also didn't updated?

    Don't get yourself bogged down here, but if the zencart team hadn't already rectified this, the "correct" fix (vs your fix) can be found here:
    http://stackoverflow.com/questions/8...-fix-available

    I'm not suggesting that you re-fix by following the example given because, well, it isn't really a problem for you to fix. It is/was something that the zencart team needed to take care of. For your part all you need do is ensure that you didn't miss anything with you upgrade (as it appears is the case)

    Cheers
    RodG

  5. #5
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: Notifier question

    Quote Originally Posted by RodG View Post
    Don't get yourself bogged down here, but if the zencart team hadn't already rectified this, the "correct" fix (vs your fix) can be found here:
    http://stackoverflow.com/questions/8...-fix-available

    I'm not suggesting that you re-fix by following the example given because, well, it isn't really a problem for you to fix. It is/was something that the zencart team needed to take care of. For your part all you need do is ensure that you didn't miss anything with you upgrade (as it appears is the case)

    Cheers
    RodG
    Regarding who to "fix" the issue, the current release of ZC 1.5.4 did not have this additional variable to pass (last modification date in github was sometime middle of last year for this one file.) The remaining plugins discussed that modify the same file are in various stages of "design" and the code of which may not have been published to the plugins area. Therefore the ZC team may not have been in a position to monitor that additional code addition.

    It would be helpful still though to identify which plugin and from where it was obtained had that additional assignment &$this so that it can be corrected for anyone else that comes across the issue.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  6. #6
    Join Date
    Mar 2005
    Posts
    229
    Plugin Contributions
    0

    Default Re: Notifier question

    Sorry guys, I thought it was clear enough, this line was only in the custom module which is a combined attribute pricing module.

    As far as I read all your replies, seems there's no danger, not today and not tomorrow in the way I changed this line.

    Thanks for your precious help

  7. #7
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: Notifier question

    Quote Originally Posted by hubert View Post
    Sorry guys, I thought it was clear enough, this line was only in the custom module which is a combined attribute pricing module.

    As far as I read all your replies, seems there's no danger, not today and not tomorrow in the way I changed this line.

    Thanks for your precious help
    The only thing that is likely to suffer (with no further action taken) is the custom module which is a combined attribute pricing module. With a little tending, any issues associated ought to be able to rectified.

    There's a format for observers written to listen to the notifiers. Further it depends on how the observer listens and what it does once it "hears" a notifier (or specifically this notifier).

    Obviously would suggest approaching the previous customizer to see what they suggest for the minor changes that are probably necessary, otherwise you're welcome to post the associated code (between code tags made by pressing the # symbol in the reply menubar) and someone will more than likely help modify the code then freely shared.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  8. #8
    Join Date
    Mar 2005
    Posts
    229
    Plugin Contributions
    0

    Default Re: Notifier question

    If I'm welcomed to post code, here it is :-)

    Code:
    <?php
    
    class OptionPricing extends base {
    	
    	var $conditions = array();
    	var $changes = array();
    	var $prices = array();
    	
    	function OptionPricing(){
    		global $zco_notifier;
    		$zco_notifier->attach($this, array(			
    			'NOTIFIER_CART_CALCULATE_ATTRIBUTE',			
    			'NOTIFIER_CART_ATTRIBUTE_PRICE_SELECT',						
    			'NOTIFY_HEADER_SHOPPING_CART_OPTION_PRICE',
    			'NOTIFY_ORDER_CART_FINISHED'
    			));
    	}
    	
    	function update(&$class, $eventID, $paramsArray) {
    		
    		switch($eventID) {
    			case 'NOTIFY_HEADER_SHOPPING_CART_OPTION_PRICE':
    			
    				$this->loadRules($paramsArray['products_id']);
    				
    				//$paramsArray->fields['options_values_price'] = 0.00;
    				
    				break;
    				
    			case 'NOTIFIER_CART_CALCULATE_ATTRIBUTE':
    			case 'NOTIFIER_CART_ATTRIBUTE_PRICE_SELECT':
    				
    				if (isset($paramsArray['cart']->contents[$paramsArray['products_id']]) && 
    				    isset($paramsArray['cart']->contents[$paramsArray['products_id']]['attributes'])){
    				    	
    				    $this->loadRules((int)$paramsArray['products_id']);
    				    				    
    					$paramsArray['options_id'] = (int)$paramsArray['options_id'];				    				    
    				    				    
    				    // look thru changes to see if this options price is ever adjusted
    				    if ( isset($this->changes[(int)$paramsArray['products_id']]) ) {
    				    	
    				    	foreach($this->changes[(int)$paramsArray['products_id']] as $ind => $pchanges){
    				    		
    				    		if (isset($pchanges[$paramsArray['options_id']])) {				    			
    				    			
    				    			$values = explode(',',$pchanges[$paramsArray['options_id']]);				    			
    				    			
    				    			//var_dump($pchanges[$paramsArray['options_id']],$values);
    				    			
    				    			if (in_array($paramsArray['options_values_id'],$values)) {
    				    				
    				    				// this option price is adjusted... check to see if conditions met.. if so, change price
    				    				if (isset($this->conditions[(int)$paramsArray['products_id']][$ind])){
    				    					$option = (int)key($this->conditions[(int)$paramsArray['products_id']][$ind]);
    				    					$value  = (int)$this->conditions[(int)$paramsArray['products_id']][$ind][$option];
    				    					
    				    					if ((isset($paramsArray['cart']->contents[$paramsArray['products_id']]['attributes'][$option]) && $paramsArray['cart']->contents[$paramsArray['products_id']]['attributes'][$option] == $value) ||
    				    					    ( isset($paramsArray['cart']->contents[$paramsArray['products_id']]['attributes'][$option.'_chk'.$value]) ) ) {
    				    						$paramsArray['rs']->fields['options_values_price'] = $this->prices[(int)$paramsArray['products_id']][$ind][$paramsArray['options_id']];
    				    					}
    				    					
    				    				}
    				    				
    				    			}
    				    		}
    				    	}
    				    }
    					
    				}
    				
    				//$paramsArray['rs']->fields['options_values_price'] = 0.00;
    								
    				break;	
    			case 'NOTIFY_ORDER_CART_FINISHED':
    				foreach($paramsArray->products as $pind => $product){										
    					if (isset($product['attributes'])) {
    						$this->loadRules($product['id']);
    						
    						foreach($this->conditions[(int)$product['id']] as $ind => $conditions){
    							
    							foreach($conditions as $option_id => $values){								
    								
    								$values = explode(',',$values);
    								foreach($values as $value){
    									$value = (int)$value;
    									foreach($product['attributes'] as $aind => $attribute){
    										if ( ($attribute['option_id'] == (int)$option_id || $attribute['option_id'] == $option_id.'_chk'.$value) &&
    										     ($attribute['value_id'] == $value) ) {
    											
    											// condition met, check for changes
    											//var_dump('ind: '.$ind,$this->changes[(int)$product['id']][$ind]);
    											foreach($this->changes[(int)$product['id']][$ind] as $coption_id => $cvalues){
    												$cvalues = explode(',',$cvalues);
    												foreach($cvalues as $cvalue){
    													$cvalue = (int)$cvalue;
    													foreach($product['attributes'] as $aind2 => $attribute2){														
    														if ( ($attribute2['option_id'] == (int)$coption_id || $attribute2['option_id'] == $coption_id.'_chk'.$cvalue) &&
    														     ($attribute2['value_id'] == $cvalue) ) {
    														     // set new price
    														     $new_price = $this->prices[(int)$product['id']][$ind][$coption_id];
    														     $paramsArray->products[$pind]['attributes'][$aind2]['price'] = $new_price;
    														}
    													}
    												}
    											}
    											
    										}
    									}	
    									
    								}																
    							}							
    						}
    						
    					}					
    					
    				}
    				break;			
    		}
    	}
    	
    	function loadRules($pID){
    		global $db;
    		
    		$pID = (int)$pID;
    		
    		if (!isset($this->conditions[$pID])) {
    			
    			$this->conditions[$pID] = array();
    			$this->changes[$pID] = array();
    			$this->prices[$pID] = array();
    			
    			$rules = $db->Execute("SELECT * FROM ".TABLE_OPTION_PRICING." WHERE products_id = ".(int)$pID);
    			while(!$rules->EOF){
    				$this->conditions[$pID][] = unserialize(base64_decode($rules->fields['conditions']));
    				$this->changes[$pID][] = unserialize(base64_decode($rules->fields['changeoptions']));
    				$this->prices[$pID][] = unserialize(base64_decode($rules->fields['prices']));
    				$rules->MoveNext();
    			}
    						
    		}		
    		
    	}
    	
    }
    This is the class I found in /includes/classes/observers/
    it fires me a bunch of debug files saying Invalid argument supplied for foreach() in line 76.
    Line 76 is
    Code:
    foreach($paramsArray->products as $pind => $product)
    But as far as I understand line 76 is not the culprit, I'm most inclined to modify the class definition beginning, replacing :

    Code:
    function OptionPricing(){
    		global $zco_notifier;
    		$zco_notifier->attach($this, array(			
    			'NOTIFIER_CART_CALCULATE_ATTRIBUTE',			
    			'NOTIFIER_CART_ATTRIBUTE_PRICE_SELECT',						
    			'NOTIFY_HEADER_SHOPPING_CART_OPTION_PRICE',
    			'NOTIFY_ORDER_CART_FINISHED'
    			));
    	}
    by

    Code:
      function __construct() {
        $this->attach($this, array('NOTIFIER_CART_CALCULATE_ATTRIBUTE',			
    			'NOTIFIER_CART_ATTRIBUTE_PRICE_SELECT',						
    			'NOTIFY_HEADER_SHOPPING_CART_OPTION_PRICE',
    			'NOTIFY_ORDER_CART_FINISHED'));
      }
    Is that solving my problem ? Would my functions still find my variables ?

  9. #9
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: Notifier question

    Issue is in fact that line, trying to bold the two locations that need to be changed below:
    Code:
    case 'NOTIFY_ORDER_CART_FINISHED':
    foreach($class->products as $pind => $product){
    if (isset($product['attributes'])) {
    $this->loadRules($product['id']);
    
    foreach($this->conditions[(int)$product['id']] as $ind => $conditions){
    
    foreach($conditions as $option_id => $values){
    
    $values = explode(',',$values);
    foreach($values as $value){
    $value = (int)$value;
    foreach($product['attributes'] as $aind => $attribute){
    if ( ($attribute['option_id'] == (int)$option_id || $attribute['option_id'] == $option_id.'_chk'.$value) &&
         ($attribute['value_id'] == $value) ) {
    
    // condition met, check for changes
    //var_dump('ind: '.$ind,$this->changes[(int)$product['id']][$ind]);
    foreach($this->changes[(int)$product['id']][$ind] as $coption_id => $cvalues){
    $cvalues = explode(',',$cvalues);
    foreach($cvalues as $cvalue){
    $cvalue = (int)$cvalue;
    foreach($product['attributes'] as $aind2 => $attribute2){
    if ( ($attribute2['option_id'] == (int)$coption_id || $attribute2['option_id'] == $coption_id.'_chk'.$cvalue) &&
         ($attribute2['value_id'] == $cvalue) ) {
         // set new price
         $new_price = $this->prices[(int)$product['id']][$ind][$coption_id];
         $class->products[$pind]['attributes'][$aind2]['price'] = $new_price;
    }
    }
    }
    }
    
    }
    }
    
    }
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  10. #10
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: Notifier question

    Ohh, and sorry, the other changes of using __construct() and the substitution of $this for $zco_notifier and removal of the global $zco_notifier are all good changes that will allow the code to operate under PHP 7.0 as well as 5.3+...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v151 Notifier help please
    By slobadog in forum General Questions
    Replies: 12
    Last Post: 7 Mar 2013, 11:14 AM
  2. Notifier trouble
    By ogradyjd in forum General Questions
    Replies: 2
    Last Post: 23 Jun 2009, 12:46 AM
  3. Notifier not Found
    By navdeep584 in forum General Questions
    Replies: 1
    Last Post: 9 Jun 2007, 06:09 PM
  4. Specific notifier question - experts please!
    By s_mack in forum General Questions
    Replies: 35
    Last Post: 22 Feb 2007, 08:01 AM
  5. Notifier Class - attempt
    By quentinjs in forum Templates, Stylesheets, Page Layout
    Replies: 20
    Last Post: 17 Oct 2006, 10:42 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR