Code:
<?php
/**
* File contains the car & tent tag building code for confirmation e-mail
*
* //@package classes
* @copyright Copyright 2017 Glenn J. Herbert (gjh42)
* @copyright Copyright 2003-2007 Zen Cart Development Team
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: order_tag_builder.php 2017-03-19 gjh42 $
*/
/*order.php line 795ff
$sql_data_array = array('orders_id' => $zf_insert_id,
...
'products_options' => $attributes_values->fields['products_options_name'],
'products_options_values' => $this->products[$i]['attributes'][$j]['value'],
...
'products_prid' => $this->products[$i]['id']
);
zen_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES, $sql_data_array);
//called from order class (order.php) by
$zco_notifier->notify('NOTIFY_ORDER_DURING_CREATE_ADDED_ATTRIBUTE_LINE_ITEM', $sql_data_array);
*/
class orderTagBuilder extends base {
function __construct() {
//global $zco_notifier; // Not needed because have extended base above.
/*$zco_notifier*/ $this->attach($this, array('NOTIFY_ORDER_DURING_CREATE_ADDED_ATTRIBUTE_LINE_ITEM','NOTIFY_ORDER_DURING_CREATE_ADD_PRODUCTS'));
//-------------------------to build tag info---------------------------------------to add tag text to content
}
/**
* Update Method
* Called by observed class when any of our notifiable events occur
* @param object $class
* @param string $eventID
*/
function update(&$class, $eventID, $paramsArray = array()) {
if(!is_array($tag_info)) global $tag_info = array(); // This will execute each time that the update class is loaded and therefore, no history will be maintained for the next load. Should instead store this variable/data in this class ($this->tag_info) if it is only going to be used herein and needs to be manipulated while this entire thing is being loaded/reused within the same load cycle.
if(!isset($tag_qty)) global $tag_qty = 0; // Same thing here as one above.
if($eventID == 'NOTIFY_ORDER_DURING_CREATE_ADDED_ATTRIBUTE_LINE_ITEM') {
if(in_array($sql_data_array[products_prid, array[7,15,17,18,24,25],true) {/*process tag info //$sql_data_array is not
defined here, and the code as written is improperly coded (missing a right side square bracket, then also the use of the
square brackets to define/declare array is incorrect unless a variable has already been somehow declared as array.
These should instead be "normal" parentheses such as (). Then the question of what is truly being sought here, as
product data in the order and shopping cart, if an attribute is included, is provided with additional information following
the products_id. So if none of these product have attributes, then you could use the "integers" provided above. If any
do have attributes but the attributes don't matter for the comparison, then something along the lines of what you have
kind of work, but the PHP syntax is wrong. To search if a key is in an array need to use array_key_exists('key', $array)
or I believe a variation of array of keys works, but I would check the PHP manual (search on 'php array_key_exists'). If trying to identify if a value is in an array, then yes in_array can work, but it would be: in_array((int)$paramsArray['products_prid'], array(7,15,17,18,24,25)) If you set the last value to true, then your internal array (array(7,15,17...)) as originally written would have required these values to be presented as strings instead of integers. But, now that the products_prid is being cast to integer, you could keep the last parameter as true if you choose, though it is unnecessary in my opinion.
if(!isset(tag_qty)) $tag_qty = 0; // unnecessary to check for isset in the current arrangement as it is "set" above.
if(!is_array($tag_info)) $tag_info = array; // also unnecessary because set above.
if($sql_data_array[products_options] == 'Name') { // $sql_data_array is not defined within this function. Perhaps you are wanting to use data that was included in $paramsArray? $sql_data_array got "absorbed" into $paramsArray, so
if you wanted to get to 'products_options' for this comparison, you would need: if ($paramsArray['products_options'] == 'Name') { //EOL
$tag_info[$tag_qty] .= '<br /><strong>-----------------------------------<br />' . $sql_data_array[products_options_value] . '</strong><br />'; // Again, products_options_value either needs to become a variable $products_options_value or needs to be referenced as a string 'products_options_value'
$tag_qty++;
}
if(in_array($sql_data_array[products_options], array['Dates','Onsite phone','Vehicle','Zone preference']) {
$tag_info[$tag_qty] .= $sql_data_array[products_options] . ': <strong>' . $sql_data_array[products_options_value] . '</strong><br />';
}
}
}
}//end build tag info
/* called by notify end of product attributes:
$zco_notifier->notify('NOTIFY_ORDER_DURING_CREATE_ADD_PRODUCTS', $custom_insertable_text);
/* START: ADD MY CUSTOM DETAILS
* 1. calculate/prepare custom information to be added to this product entry in order-confirmation.
* 2. Add that data to the $this->products_ordered_attributes variable, using this sort of format:
* $this->products_ordered_attributes .= {INSERT CUSTOM INFORMATION HERE};
*/
if ($eventID == 'NOTIFY_ORDER_DURING_CREATE_ADD_PRODUCTS') {
if(is_array($tag_info)) {//add tags if they exist // This won't be set because once this function is complete, $tag_info falls out of scope... So $tag_info will actually be unset when this notifier is reached during execution. But, if this class which had been generated earlier in the load stored that value (as discussed in the observer section above), then so long as the entire system hasn't reloaded, this class will still have any values that were maintained... To do this use: $this->tag_info to store/retrieve data associated with this class.
foreach($tag_info[] as $tag_qty,$tag_text) {
$custom_insertable_text .= '<br /><br /><br />';
if(strpos($tag_text,'Vehicle') /== false) {//add car tag The symbol before the double equals should be an exclamation point, not a forward slash, that could be another reason the code has failed to load/500 error.
$custom_insertable_text .= '
<br /><br /><br /><h2><strong>------------------------------------------<br />CAR TAG</strong></h2><br />' . $tag_text . '<br /><br /><br />';
}
//add tent tag
$custom_insertable_text .= '
<h2><strong>------------------------------------------<br />TENT TAG</strong></h2><br />' . $tag_text . '<br /><br /><br />';
}
}
$this->products_ordered_attributes .= $custom_insertable_text;//can i do this here? // yes if you use $class->products_ordered_attributes, otherwise, as written you are directing to store the data within this class and not passing it back to program flow.
unset $tag_info, $tag_qty;//in case the customer wants to make another order // This actually is more about clearing memory as in proper program flow, this class should get its values reset when initiated which occurs on a page load, thus if they were to complete a purchase the data associated that is not placed/controlled by a $_SESSION type value will be lost. Proof? Set a value in one of the header files that won't be loaded at the point of reviewing the result(s). Ie. goto the contact_us header file and add a variable of some type, then go to another header file and echo that variable out. Then navigate to the contact_us page and then navigate to the page that is supposed to export the value... Not there... Sooo... The unset simply clears the associated memory of those variables which in this situation, there's other factors that could be at play, but basically if I remember scope rules correctly, they will be unset in this function but when going back out of the function they will be as if they never were altered, that might be a specific PHP version situation, I can't recall at the moment, but I also don't unset variables that are intended to be global or reused within the existing code unless I specifically have a test that will reinstate them for reach load in which they would be needed again, which are somewhat done here, but not quite right....
}//end add tag text to content
}
//eof
Bookmarks