Just a quick follow up, and this may be too much to ask, but what would it take to display the swapped image in the cart?
I think that would be a great addition to the script and will avoid potential confusion with the customer.
Just a quick follow up, and this may be too much to ask, but what would it take to display the swapped image in the cart?
I think that would be a great addition to the script and will avoid potential confusion with the customer.
So, I have/had already incorporated something into Stock By Attributes that does that, guess could add to this plugin a way to incorporate the functionality if it didn't/doesn't already exist.
See the function that begins here: https://github.com/mc12345678/Stock_...stock.php#L936
With the "meat" between lines 1024 and 1071 (though need to get through a few if statements to activate that code portion)
ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...
Here is what I came up with that works for me, with my limited hobbyist coding level.
includes/functions/extra_functions/functions_ais_cart.php
LINE 67 tpl_shopping_cart_default.phpPHP Code:
<?php
/**
* includes/functions/extra_functions/functions_ais_cart.php
* ais
*
* @author DavidV
* @license http://www.gnu.org/licenses/gpl.txt GNU General Public License V2.0
* @version $Id: functions_ais_cart.php,v 1.0 Rev 1 2018-04-06 13:52:50
* Last modified by DavidV 2018-04-06 13:52:50
*/
/**
* Displays attribute images in cart for Attribute Image Swap 6 (AIS)
*/
function ais_cart_img_data($id,$attr){
global $db;
$sql = "SELECT attributes_image,options_values_id
from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib
where patrib.products_id=" . (int)$id . "
and patrib.options_id = popt.products_options_id
and popt.language_id = " . (int)$_SESSION['languages_id'] . "
and (popt.products_options_images_style = 6 OR popt.products_options_images_style = 8)";
$result = $db->Execute($sql);
return $result;
}
function ais_cart_img($id,$attr,$img,$img_name) {
$ais_support = defined('ATTRIBUTES_ENABLED_IMAGES') && ATTRIBUTES_ENABLED_IMAGES == 'true' && zen_has_product_attributes((int)$id);
if ($ais_support) {
$result = ais_cart_img_data($id,$attr);
if ($result->RecordCount() > 0){
$attr_cart = array();
foreach ($attr as $attrval)
array_push($attr_cart[$attrval['options_values_id']]);
$attr_all = array();
while (!$result->EOF) {
$attr_all[$result->fields['options_values_id']] = $result->fields['attributes_image'];
$result->MoveNext();
}
$img_attr = current(array_intersect_key($attr_all,$attr_cart));
if($img_attr)
return zen_image(DIR_WS_IMAGES.$img_attr,$img_name);
else
return $img;
}
else
return $img;
}
else
return $img;
}
Replaced:
With:PHP Code:
<?php echo $product['productsImage']; ?>
I am sure there is a more elegant way to do this but it serves the purpose for now.PHP Code:
<?php echo ais_cart_img($product['id'],$product['attributes'],$product['productsImage'],$product['productsName']); ?>
Once again, thankls for all your help!
Slight change to functions_ais_cart.php
ais_cart_img_data only needs an $id argument.
Also further consolidated the code.
PHP Code:
<?php
/**
* includes/functions/extra_functions/functions_ais_cart.php
* @author DavidV (dvtalk)
* @license http://www.gnu.org/licenses/gpl.txt GNU General Public License V2.0
* @version $Id: functions_ais_cart.php,v 1.0.1 2018-04-07
* Displays attribute images in cart for Attribute Image Swap 6 (AIS)
*/
function ais_cart_img_data($id){
global $db;
$sql = "SELECT attributes_image,options_values_id
from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib
where patrib.products_id=" . (int)$id . "
and patrib.options_id = popt.products_options_id
and popt.language_id = " . (int)$_SESSION['languages_id'] . "
and (popt.products_options_images_style = 6 OR popt.products_options_images_style = 8)";
return $db->Execute($sql);
}
function ais_cart_img($id,$attr,$img,$img_name) {
$img_attr = false;
$ais_support = defined('ATTRIBUTES_ENABLED_IMAGES') && ATTRIBUTES_ENABLED_IMAGES == 'true' && zen_has_product_attributes((int)$id);
if ($ais_support) {
$result = ais_cart_img_data($id);
if ($result->RecordCount() > 0){
$attr_cart = array();
foreach ($attr as $attrval)
array_push($attr_cart[$attrval['options_values_id']]);
$attr_all = array();
while (!$result->EOF) {
$attr_all[$result->fields['options_values_id']] = $result->fields['attributes_image'];
$result->MoveNext();
}
$img_attr = current(array_intersect_key($attr_all,$attr_cart));
}
}
if($img_attr)
return zen_image(DIR_WS_IMAGES.$img_attr,$img_name);
else
return $img;
}
Last edited by dvtalk; 7 Apr 2018 at 07:25 AM.
One more edit. array_push() was improperly used.
PHP Code:
<?php
/**
* includes/functions/extra_functions/functions_ais_cart.php
* @author DavidV (dvtalk)
* @license http://www.gnu.org/licenses/gpl.txt GNU General Public License V2.0
* @version $Id: functions_ais_cart.php,v 1.0.1 2018-04-07
* Displays attribute images in cart for Attribute Image Swap 6 (AIS)
*/
function ais_cart_img_data($id){
global $db;
$sql = "SELECT attributes_image,options_values_id
from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib
where patrib.products_id=" . (int)$id . "
and patrib.options_id = popt.products_options_id
and popt.language_id = " . (int)$_SESSION['languages_id'] . "
and (popt.products_options_images_style = 6 OR popt.products_options_images_style = 8)";
return $db->Execute($sql);
}
function ais_cart_img($id,$attr,$img,$img_name) {
$img_attr = false;
$ais_support = defined('ATTRIBUTES_ENABLED_IMAGES') && ATTRIBUTES_ENABLED_IMAGES == 'true' && zen_has_product_attributes((int)$id);
if ($ais_support) {
$result = ais_cart_img_data($id);
if ($result->RecordCount() > 0){
$attr_cart = array();
foreach ($attr as $attrval)
$attr_cart[$attrval['options_values_id']]=1;
$attr_all = array();
while (!$result->EOF) {
$attr_all[$result->fields['options_values_id']] = $result->fields['attributes_image'];
$result->MoveNext();
}
$img_attr = current(array_intersect_key($attr_all,$attr_cart));
}
}
if($img_attr)
return zen_image(DIR_WS_IMAGES.$img_attr,$img_name);
else
return $img;
}
Used a different approach but have incorporated some similar operation into what is to be considered version 1.5.9 of this plugin (including other corrections/changes). This uses the notifier for the shopping_cart page (no template file editing) to replace the product image with the attribute image swapped image. Can see this arrangement at: https://github.com/mc12345678/Attrib...ap/tree/v1.5.9
ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...
Thank you for this. I went ahead and downloaded the 1.5.9 from Github. Everything seems to be working woderfully, but I wonder if you can help me figure this out:
I am using an image plugin that displays a product zoom and I am attempting to merge the attributes.php file.
Your code is inserting $params into the select field, outputting:
<div class="select-wrapper"><select name="id[35]" id="attrib-35" onchange="getattribimage('id[35]', 450, 0, this.value, 508);">
Their code is simply:
<div class="select-wrapper"><select name="id[35]" id="attrib-35">
If I add the $params to the select, it breaks their code. If I don't insert the $params, then the image swap doesn't work.
Can you please point me to the right direction on where to lok for the conflict?
Thanks,
David
"Their" method uses the standard attribute build which means that they also use javascript to initiate the action. How the javascript attaches and loads should help to resolve the issue. Would look to follow the javascript from page load to attribute change. (Most browsers support such action/operation.)
ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...
Bookmarks