Re: Dynamic Price Updater
After looking at the error couple of times I figured out how to fix the problem, hopefully my fix is not going to kick me back :lamo: We will find out in the next couple of weeks, but here it goes:
Code:
for (var i=0; objInp[i]; i++) {
if (objInp[i].type == 'radio' || objInp[i].type == 'checkbox') { // make sure we're dealing with radio boxes
db = 'Name - ' + objInp[i].name + ' : ID - ' + objInp[i].id;
//Fred C fix
if(objInp[i].nextSibling != null){
//end Fred C fix
matches = objInp[i].nextSibling.innerHTML.match(seeker);
if (matches) {
db += ' : Adjusted!';
objInp[i].onclick = function () { updateR(this); }
if (objInp[i].checked) updateR(objInp[i]);
}
}
//Fred C fix
}
//end Fred C fix
regdb('Onload RAD/CH', db);
}
Fred. :smile:
Re: Dynamic Price Updater
Quote:
Originally Posted by
Ajeh
The display is manage by the class in the template ... so I made the one at the top use a different class so the price did not change and put one at the bottom where the add to cart quantity is put in that had the class that gets changed ...
This way, the original price always shows on the page and the changing price of what the "actual" price will be based on quantity etc. would show right where the customer is working down by the attributes and add to cart quantity box ...
Hi Linda,
I failed to make DPU still showing the original price (didn't chnaged), instead of replacing it by just 'Your price: xxxx' because we have special price, so we can show how both original price and discount price.
I tried your method building a new class, above but couldn't get it to work, can you show me example of the file you modified?
I mean the file:
/classes/dynamic_price_updater.php
Thanks so much!
Re: Dynamic Price Updater
From what I remember on this one the:
zen_get_products_display_price
was in the :
<h2 id="productPrices" class="productGeneral">
and the update prices affect that ...
I just repeated the code without that and used a new class ...
Re: Dynamic Price Updater
I've installed this mod and it's working well. I've also installed this mod (http://www.zen-cart.com/forum/showthread.php?t=98641) to enable me to have a drop down menu on the product listing page rather than just the product info page. How would I go about having the price on that page dynamically update just like it does with the product info page?
Re: Dynamic Price Updater
To add a little bit more to my previous post...here is a link to my work-in-progress: https://www.mcqueeneycoins.com/index...ndex&cPath=1_2 showing the attribute drop-down mod in action.
On this page I want the prices to dynamically update when an attribute is selected, just as it does on the individual product's page. If anyone can shed some light on this for me I'm forever in your debt.
Thanks!
Re: Dynamic Price Updater
has anyone got an idea how to get this working with dual pricing- wholesale, and replace product images on attribute change? i know this has been asked before and i know you have a long list of stuff to do dan, but if you could point me in the right direction i might be able to figure it out, also i am willing to make a donation if you could get these 2 working with this mod.
i have a test set up here:
http://southcrystals.com/index.php?m...products_id=22
i had both of these mods working before DPUv2
this is zc 1.3.8a
and if you need ftp in order to help me out just let me know.
also how do i remove the product quantity in parenthesis?
thank you so much for all of your time and energy into this dan, i have read through almost everythread of this topic and used a few of your fixes aready to get it working so far, but i do really need these other two working as well, as they took me forever to get working too.
Re: Dynamic Price Updater
ok, so i am assuming that the file that mainly needs to be edited is
includes/classes/dynamic_price_updater.php (to get the dual price - wholesale price mod to work)
here is what i have changed it to
Code:
<?php
// (c) D Parry (Chrome) 2009 ([email protected])
// This module is free to distribute and use as long as the above copyright message is left in tact
class DPU {
/**
* Current Zen Cart database object
*
* @var object
*/
var $_db;
/**
* Local copy of the POST array
*
* @var array
*/
var $_post = array();
/**
* Local instantiation of the shopping cart
*
* @var object
*/
var $_shoppingCart;
/**
* The type of message being sent (error or success)
*
* @var string
*/
var $_responseType = 'success';
/**
* Array of lines to be sent back. The key of the array provides the attribute to identify it at the client side
* The array value is the text to be inserted into the node
*
* @var array
*/
var $_responseText = array();
/**
* Constructor
*
* @param obj The Zen Cart database class
* @return DPU
*/
function __construct(&$db) {
$this->_db =& $db;
$this->_post =& $_POST;
// grab the shopping cart class and instantiate it
require_once(DIR_WS_CLASSES.'shopping_cart.php');
$this->_shoppingCart = new shoppingCart();
}
/**
* PHP4 constructor
*
* @param obj ZC DB object
* @return DPU
*/
function DPU(&$db) {
$this->__construct($db);
}
/**
* Wrapper to call all methods to generate the output
*
* @return void
*/
function getDetails() {
$this->insertProduct();
$this->_shoppingCart->calculate();
if (DPU_SHOW_SIDEBOX) $this->getSideboxContent();
$this->prepareOutput();
$this->dumpOutput();
}
/**
* Wrapper to call all methods relating to returning multiple prices for category pages etc.
*
* @return void
*/
function getMulti() {
$this->insertProducts();
}
/**
* Prepares the shoppingCart contents for transmission
*
* @return void
*/
function prepareOutput() {
global $currencies;
$this->_responseText['priceTotal'] = UPDATER_PREFIX_TEXT;
$product_check = $this->_db->Execute("select products_tax_class_id from " . TABLE_PRODUCTS . " where products_id = '" . (int)$this->_post['products_id'] . "'" . " limit 1");
if (false == DPU_SHOW_CURRENCY_SYMBOLS) {
$this->_responseText['priceTotal'] .= number_format($this->_shoppingCart->total, 2);
} else {
$this->_responseText['priceTotal'] .= $currencies->display_price($this->_shoppingCart->total, $product_check->fields['products_tax_class_id']);
}
$this->_responseText['weight'] = (string)$this->_shoppingCart->weight;
if (DPU_SHOW_QUANTITY) {
$this->_responseText['quantity'] = sprintf(DPU_SHOW_QUANTITY_FRAME, $this->_shoppingCart->contents[$this->_post['products_id']]['qty']);
}
}
/**
* Inserts multiple non-attributed products into the shopping cart
*
* @return void
*/
function insertProducts() {
foreach ($this->_post['products_id'] as $id => $qty) {
$this->_shoppingCart->contents[] = array($id);
$this->_shoppingCart->contents[$id] = array('qty' => (float)$qty);
}
var_dump($this->_shoppingCart);
die();
}
/**
* Inserts the product into the shoppingCart content array
*
* @returns void
*/
function insertProduct() {
$this->_shoppingCart->contents[$this->_post['products_id']] = array('qty' => (float)$this->_post['cart_quantity']);
$attributes = array();
foreach ($this->_post as $key => $val) {
if (is_array($val)) {
foreach ($val as $k => $v) {
$attributes[$k] = $v;
}
}
}
if (is_array($attributes)) {
reset($attributes);
while (list($option, $value) = each($attributes)) {
//CLR 020606 check if input was from text box. If so, store additional attribute information
//CLR 020708 check if text input is blank, if so do not add to attribute lists
//CLR 030228 add htmlspecialchars processing. This handles quotes and other special chars in the user input.
$attr_value = NULL;
$blank_value = FALSE;
if (strstr($option, TEXT_PREFIX)) {
if (trim($value) == NULL) {
$blank_value = TRUE;
} else {
$option = substr($option, strlen(TEXT_PREFIX));
$attr_value = stripslashes($value);
$value = PRODUCTS_OPTIONS_VALUES_TEXT_ID;
$this->_shoppingCart->contents[$this->_post['products_id']]['attributes_values'][$option] = $attr_value;
}
}
if (!$blank_value) {
if (is_array($value) ) {
reset($value);
while (list($opt, $val) = each($value)) {
$this->_shoppingCart->contents[$this->_post['products_id']]['attributes'][$option.'_chk'.$val] = $val;
}
} else {
$this->_shoppingCart->contents[$this->_post['products_id']]['attributes'][$option] = $value;
}
}
}
}
// $this->_shoppingCart->cleanup();
}
/**
* Prepares the output for the Updater's sidebox display
*
*/
function getSideboxContent() {
global $currencies;
$product_check = $this->_db->Execute("select products_tax_class_id from " . TABLE_PRODUCTS . " where products_id = '" . (int)$this->_post['products_id'] . "'" . " limit 1");
$product_query = "select products_id, products_price, products_tax_class_id, products_weight,
products_priced_by_attribute, product_is_always_free_shipping, products_discount_type, products_discount_type_from,
products_virtual, products_model
from " . TABLE_PRODUCTS . "
where products_id = '" . (int)$this->_post['products_id'] . "'";
$product = $this->_db->Execute($product_query);
$prid = $product->fields['products_id'];
$products_tax = zen_get_tax_rate($product->fields['products_tax_class_id']);
// $products_price = $product->fields['products_price']; - REMOVED FOR DUAL PRICING MOD
//*************************************************************
//***** CHECK WHETHER WHOLESALE OR RETAIL AND GET CORRECT PRICE
//*************************************************************
if ($_SESSION['customer_id']) {
$customers_id = $_SESSION['customer_id'];
$customer_check = $db->Execute("select * from " . TABLE_CUSTOMERS . " where customers_id = '$customers_id'");
if ($customer_check->fields['customers_whole'] != "0") {
$i = $customer_check->fields['customers_whole'];
$i = $i-1;
$products_price_array = $product->fields['products_price_w'];
$productsprice = explode("-",$products_price_array);
$products_price = $productsprice[$i];
if ($products_price == '0' || $products_price == '') {
$products_price = $productsprice[0];
}
if ($products_price=='0'){
$products_price = $product->fields['products_price'];
}
} else {
$products_price = $product->fields['products_price'];
}
} else {
$products_price = $product->fields['products_price'];
}
//****************************************************************
//*****END CHECK WHETHER WHOLESALE OR RETAIL AND GET CORRECT PRICE
//****************************************************************
$qty = $this->_post['cart_quantity'];
$out = array();
$global_total;
reset($this->_shoppingCart->contents[$this->_post['products_id']]['attributes']);
while (list($option, $value) = each($this->_shoppingCart->contents[$this->_post['products_id']]['attributes'])) {
$adjust_downloads ++;
$attribute_price_query = "select *
from " . TABLE_PRODUCTS_ATTRIBUTES . "
where products_id = '" . (int)$prid . "'
and options_id = '" . (int)$option . "'
and options_values_id = '" . (int)$value . "'";
$attribute_price = $this->_db->Execute($attribute_price_query);
$sql = "SELECT
`products_options_values_name`
FROM
".TABLE_PRODUCTS_OPTIONS_VALUES."
WHERE
`products_options_values_id` = $value";
$data = $this->_db->Execute($sql);
$name = $data->fields['products_options_values_name'];
$new_attributes_price = 0;
$discount_type_id = '';
$sale_maker_discount = '';
$total = 0;
if ($attribute_price->fields['product_attribute_is_free'] == '1' and zen_get_products_price_is_free((int)$prid)) {
// no charge for attribute
} else {
// + or blank adds
if ($attribute_price->fields['price_prefix'] == '-') {
// appears to confuse products priced by attributes
if ($product->fields['product_is_always_free_shipping'] == '1' or $product->fields['products_virtual'] == '1') {
$shipping_attributes_price = zen_get_discount_calc($product->fields['products_id'], $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty);
$this->free_shipping_price -= $qty * zen_add_tax( ($shipping_attributes_price), $products_tax);
}
if ($attribute_price->fields['attributes_discounted'] == '1') {
// calculate proper discount for attributes
$new_attributes_price = zen_get_discount_calc($product->fields['products_id'], $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty);
$total -= $qty * zen_add_tax( ($new_attributes_price), $products_tax);
} else {
$total -= $qty * zen_add_tax($attribute_price->fields['options_values_price'], $products_tax);
}
$total = '-'.$total;
} else {
// appears to confuse products priced by attributes
if ($product->fields['product_is_always_free_shipping'] == '1' or $product->fields['products_virtual'] == '1') {
$shipping_attributes_price = zen_get_discount_calc($product->fields['products_id'], $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty);
$this->free_shipping_price += $qty * zen_add_tax( ($shipping_attributes_price), $products_tax);
}
if ($attribute_price->fields['attributes_discounted'] == '1') {
// calculate proper discount for attributes
$new_attributes_price = zen_get_discount_calc($product->fields['products_id'], $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty);
$total += $qty * zen_add_tax( ($new_attributes_price), $products_tax);
// echo $product->fields['products_id'].' - '.$attribute_price->fields['products_attributes_id'].' - '. $attribute_price->fields['options_values_price'].' - '.$qty."\n";
// $products_price = $product->fields['products_price']; - REMOVED FOR DUAL PRICING MOD
//*************************************************************
//***** CHECK WHETHER WHOLESALE OR RETAIL AND GET CORRECT PRICE
//*************************************************************
if ($_SESSION['customer_id']) {
$customers_id = $_SESSION['customer_id'];
$customer_check = $db->Execute("select * from " . TABLE_CUSTOMERS . " where customers_id = '$customers_id'");
if ($customer_check->fields['customers_whole'] != "0") {
$i = $customer_check->fields['customers_whole'];
$i = $i-1;
$products_price_array = $products->fields['products_price_w'];
$productsprice = explode("-",$products_price_array);
$products_price = $productsprice[$i];
if ($products_price == '0' || $products_price == '') {
$products_price = $productsprice[0];
}
if ($products_price=='0'){
$products_price = $products->fields['products_price'];
}
} else {
$products_price = $products->fields['products_price'];
}
} else {
$products_price = $products->fields['products_price'];
}
//****************************************************************
//*****END CHECK WHETHER WHOLESALE OR RETAIL AND GET CORRECT PRICE
//****************************************************************
} else {
$total += $qty * zen_add_tax($attribute_price->fields['options_values_price'], $products_tax);
}
}
}
$global_total += $total;
$qty2 = sprintf(DPU_SIDEBOX_QUANTITY_FRAME, $this->_post['cart_quantity']);
$total = sprintf(DPU_SIDEBOX_PRICE_FRAME, $currencies->display_price($total, $product_check->fields['products_tax_class_id']));
$out[] = sprintf(DPU_SIDEBOX_FRAME, $name, $total, $qty2);
}
$out[] = sprintf(DPU_SIDEBOX_TOTAL_FRAME, $currencies->display_price($this->_shoppingCart->total, $product_check->fields['products_tax_class_id']));
$qty2 = sprintf(DPU_SIDEBOX_QUANTITY_FRAME, $this->_post['cart_quantity']);
$total = sprintf(DPU_SIDEBOX_PRICE_FRAME, $currencies->display_price($this->_shoppingCart->total-$global_total, $product_check->fields['products_tax_class_id']));
array_unshift($out, sprintf(DPU_SIDEBOX_FRAME, 'Base price', $total, $qty2));
$this->_responseText['sideboxContent'] = implode('', $out);
}
/**
* Performs an error dump
*
* @param mixed $errorMsg
*/
function throwError($errorMsg) {
$this->_responseType = 'error';
$this->_responseText[] = $errorMsg;
$this->dumpOutput();
}
/**
* Formats the response and flushes with the appropriate headers
* This should be called last as it issues an exit
*
* @return void
*/
function dumpOutput() {
// output the header for XML
header ("content-type: text/xml");
// set the XML file DOCTYPE
echo '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
// set the responseType
echo '<root>'."\n".'<responseType>'.$this->_responseType.'</responseType>'."\n";
// now loop through the responseText nodes
foreach ($this->_responseText as $key => $val) {
echo '<responseText'.(!is_numeric($key) && !empty($key) ? ' type="'.$key.'"' : '').'><![CDATA['.$val.']]></responseText>'."\n";
}
die('</root>');
}
}
i know i am not doing this right, i see that i have inserted the wholesale code into a function, and im not good with this stuff, but i will keep playing around.
Re: Dynamic Price Updater
i have figured why (i think) i cannot get this to work.
it is calculating from priceTotal which is from the price update mod only, so it will not show any other prices. i am unsure how to merge these....
i will leave it alone for now, but ANY ideas are welcome, thank you!
Re: Dynamic Price Updater
Hi!,
I install this tool and works ok, but then the "attribute replace main product image" donīt work.
I want that when customer select an attribute, for example a color that is moore expensive, the main product image and price change to the new image and price.
Separately the DPU and "attribute replace main product image" works ok, but not together.
Anyone knows how can I obtain this effect or why this two modules donīt work together?
Thank you very much.