Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Join Date
    Dec 2008
    Location
    Pittsburgh, PA
    Posts
    237
    Plugin Contributions
    1

    Default Change Product Price on Check-out (if on admin computer)

    so I've been trying to add a bit of clever coding to my website so I can change the price of products as I'm checking out a customer from my store's computer.

    I've been trying to get the displayed product price to become an input field (within some if shop's computer ip address logic)

    I've added
    $productsPriceEach = zen_draw_input_field('cart_price[]', $products[$i]['price'], 'size="4" class="cart_input_'.$products[$i]['id'].'"');
    around line 153 of includes/modules/pages/shopping_cart/header.php

    and then I echo that out in the tpl_shopping_cart_default.php

    I was trying to add that field to the from submitted
    Code:
    <form name="cart_quantity" action="http://www.mydomain.com/index.php?main_page=shopping_cart&amp;action=update_product" method="post">
    then that action 'update_product'

    takes you to...
    case 'update_product' :
    $_SESSION['cart']->actionUpdateProduct($goto, $parameters);

    then in shopping_cart.php function actionUpdateProduct(

    I tried to add
    $new_price = $_POST['cart_price'][$i]; // new quantity
    $new_price = $this->adjust_price($new_price, $_POST['products_id'][$i], 'shopping_cart');

    one bracket above
    zen_redirect(zen_href_link($goto, zen_get_all_get_params($parameters)));

    I even copied the logic for function adjust_quantity( to become the function adjust_price. and then commented it mostly out to just return the $new_price.

    Now it's late and I think I'm kinda stuck, if anyone has and helpful thoughts on things to echo, I have yet to really see a value I've submitted through the input field. Shouldn't I be able to pull up a print_r($_POST) on this update_quantity function?

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

    Default Re: Change Product Price on Check-out (if on admin computer)

    Better off doing something like:
    Code:
    trigger_error($_POST, E_USER_WARNING);
    At opportune points. The $_POST variable gets modified on redirect so you want to do what is needed before the redirect to ensure that the desired data is maintained available where it is next needed.

    There are other ways to "temporarily" see the data associated with the internal code such as using the display globals plugin and storage of data in such a way that it can be reviewed for conditions such as loops, multiple redirects, etc...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

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

    Default Re: Change Product Price on Check-out (if on admin computer)

    Quote Originally Posted by mc12345678 View Post
    Better off doing something like:
    Code:
    trigger_error($_POST, E_USER_WARNING);
    At opportune points. The $_POST variable gets modified on redirect so you want to do what is needed before the redirect to ensure that the desired data is maintained available where it is next needed.

    There are other ways to "temporarily" see the data associated with the internal code such as using the display globals plugin and storage of data in such a way that it can be reviewed for conditions such as loops, multiple redirects, etc...
    Actually, since the $_POST variable is an array, you'll need
    Code:
    trigger_error(var_export($_POST, true), E_USER_WARNING);

  4. #4
    Join Date
    Dec 2008
    Location
    Pittsburgh, PA
    Posts
    237
    Plugin Contributions
    1

    Default Re: Change Product Price on Check-out (if on admin computer)

    Am I overlooking something or is the in_cart_product_total_price($product_id) function in includes/classes/shopping_cart.php never called?

    I have the one page checkout add-on installed so maybe the developer's tool-kit only searches used files?

    sidenote: I installed lat9's superglobal's add-on it seems quite helpful although I think I'm going to have to study this code quite a bit more before I can figure out why $_POST never holds anything.

    The update quantity portion seems to hold values in $_SESSION['cart']['contents'][$product_id]['qty']
    so perhaps if I can get the new price into that format I'll be on the right path.

    I wasn't able to get the trigger_error to show anything at least in the places I put it, probably at least according to superglobals add-on the $_POST variable is empty w/ what I'm trying.

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Re: Change Product Price on Check-out (if on admin computer)

    You're not overlooking anything, those functions are defined but unused.

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

    Default Re: Change Product Price on Check-out (if on admin computer)

    trigger_error would not put anything to screen, it creates a myDebug log in the logs folder. If you wanted to have information in the superglobals plugin, then would need to capture data in a superglobal related variable. Just understand that what it reports is the "last" value that is held, not necessarily how the variable changes over time/execution.

    Ie. If were to use $_SESSION['myVar'] = $myVarData; and that was within a loop, you would only see 1) whether the loop was executed the very first time that were looking at the superglobals plugin was active or if it was not executed, and 2) if it were executed what the value was at the last time it was executed....

    This assumes also that the session variable was not unset at some point before it's first use or provided some other "default" value...

    A lot of ways around this, but if determined to track information "uniquely" through such iterations, would suggest developing some sort of scheme that supports understanding the data seen. Ie. Using a counter within a loop where the number of times to loop is executed can be factored in, clearing such session variables before their use, ie. using a session variable that is an array where each element of the array provides a piece of data but the original session variable can be cleared by either unsetting the session variable or setting it to an empty array...

    I hope that something from the above is understood, if not yet then probably will be more so after trying to actually store some value(s) to review...

    As said, there are a lot of ways to collect data along the execution path.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  7. #7
    Join Date
    Apr 2007
    Location
    Ontario, Canada
    Posts
    1,731
    Plugin Contributions
    27

    Default Re: Change Product Price on Check-out (if on admin computer)

    Quote Originally Posted by wolfderby View Post
    so I've been trying to add a bit of clever coding to my website so I can change the price of products as I'm checking out a customer from my store's computer.

    I've been trying to get the displayed product price to become an input field (within some if shop's computer ip address logic)

    I've added
    $productsPriceEach = zen_draw_input_field('cart_price[]', $products[$i]['price'], 'size="4" class="cart_input_'.$products[$i]['id'].'"');
    around line 153 of includes/modules/pages/shopping_cart/header.php

    and then I echo that out in the tpl_shopping_cart_default.php

    I was trying to add that field to the from submitted
    Code:
    <form name="cart_quantity" action="http://www.mydomain.com/index.php?main_page=shopping_cart&amp;action=update_product" method="post">
    then that action 'update_product'

    takes you to...
    case 'update_product' :
    $_SESSION['cart']->actionUpdateProduct($goto, $parameters);

    then in shopping_cart.php function actionUpdateProduct(

    I tried to add
    $new_price = $_POST['cart_price'][$i]; // new quantity
    $new_price = $this->adjust_price($new_price, $_POST['products_id'][$i], 'shopping_cart');

    one bracket above
    zen_redirect(zen_href_link($goto, zen_get_all_get_params($parameters)));

    I even copied the logic for function adjust_quantity( to become the function adjust_price. and then commented it mostly out to just return the $new_price.

    Now it's late and I think I'm kinda stuck, if anyone has and helpful thoughts on things to echo, I have yet to really see a value I've submitted through the input field. Shouldn't I be able to pull up a print_r($_POST) on this update_quantity function?
    If you install login as customer from admin alongside Twitch Wholesale or Twitch Restrict you can use the filters to show custom products that show for admin only on any customer or add admin only filters that will allow you to modify the product on screen and send the data natively through the cart.

    This method maintains the integrity of the security measures already built into the cart and ensures order total calculations are always spot on.
    Twitch.
    https://www.twitchtoo.com Do you work for free? Please donate.
    Twitch Base8 - Obsidian - This, is what's new.

  8. #8
    Join Date
    Dec 2008
    Location
    Pittsburgh, PA
    Posts
    237
    Plugin Contributions
    1

    Default Re: Change Product Price on Check-out (if on admin computer)

    thanks for the replies everyone.

    I've seen my new price in the debug logs w/ the trigger_error, but I'm still trying to figure out where to place that data for it to temporarily change the price. I'm ok w/ struggling with this step though for now, because I'm hoping to understand zen-cart better. I'm thinking I might try to put it in a $_SESSION['product'] object/array and to "if(isset($_SESSION['product']['id']['new_price']) else (original zen code)" -it on lines where it pulls data from the products object/class/table otherwise.

    includes/modules/pages/shopping_cart/header_php.php

    quick question for better understanding though (beyond css styling...) can anyone explain to me the class of:
    Code:
    $quantityField = zen_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4" class="cart_input_'.$products[$i]['id'].'"');
    for example this might become:
    Code:
    <input type="text" name="cart_quantity[]" value="1" size="4" class="cart_input_10203">
    assuming the product_id is 10203

    ...what does this class do?
    Last edited by wolfderby; 9 Mar 2018 at 10:34 PM.

  9. #9
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Re: Change Product Price on Check-out (if on admin computer)

    That class could be used to style (via CSS) the way that quantity box is displayed on a product-by-product basis. You'd create a file in your active template's /css directory named shopping_cart.css and add something akin to

    Code:
    .cart_input_10203 { border: 1px solid red; }
    ... assuming that you wanted the quantity box to look different for different products. See the CSS_read_me.txt file, present in the /template_default/css directory, for additional information.

  10. #10
    Join Date
    Dec 2008
    Location
    Pittsburgh, PA
    Posts
    237
    Plugin Contributions
    1

    Default Re: Change Product Price on Check-out (if on admin computer)

    cool, so no other purpose other than styling?

    Also I got my edit to work by editing the includes/classes/order.php
    Code:
    function cart() {
    
    ...
    
    $this->products[$index] = array('...
    
    'price' => (isset($_SESSION['new_price'][$products[$i]['id']]) ? $_SESSION['new_price'][$products[$i]['id']] : $products[$i]['price']),
    and
    'final_price' => zen_round((isset($_SESSION['new_price'][$products[$i]['id']]) ? $_SESSION['new_price'][$products[$i]['id']] : $products[$i]['price'] + $_SESSION['cart']->attributes_price($products[$i]['id'])), 4), // changed to 4 decimals for rounding calcs -- frank18
    
    
    }
    and I put the data there in includes/classes/shopping_cart.php
    Code:
    function actionUpdateProduct($goto, $parameters) {...
    ...
    if ( in_array($_POST['products_id'][$i],  ... else {
    ...
     $_SESSION['new_price'][$_POST['products_id'][$i]] = $_POST['cart_price'][$i];
    }
    within the last else



    is it bad to have the double square bracket for $_SESSION['new_price'][$_POST['products_id'][$i]] ?

    Also is there a way to tell which php pages have been used to load a page? and/or the order of the object's methods? I think that was the most confusing part of figuring this out. The superglobals add-on for me really revealed how much goes into even just one page loading.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v153 Sold Out product change price to zero
    By Mattvickauto in forum General Questions
    Replies: 1
    Last Post: 6 Dec 2014, 07:49 PM
  2. Attribute price not showing up in sub-total or check-out
    By tcarden in forum Setting Up Categories, Products, Attributes
    Replies: 6
    Last Post: 25 Jan 2013, 09:25 PM
  3. Where to change the color of box headers in check out?
    By samuxul in forum Templates, Stylesheets, Page Layout
    Replies: 6
    Last Post: 1 Dec 2011, 06:59 PM
  4. Change Table Rate (best way) on check out
    By chris32882 in forum General Questions
    Replies: 4
    Last Post: 9 Nov 2008, 07:42 PM
  5. NO Admin, Log-in, or Check-Out
    By gloow in forum General Questions
    Replies: 1
    Last Post: 25 Apr 2007, 09:14 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