Cindy,
I've been trying out OPC with guest checkout and it works great. But I'd like to apply the group discount to certain guests. I've set up an observer to check if a guest customer should get a discount when the guest enters their name and address. If so, I set the group_pricing field in the customers table for the special "do not remove" guest customers_id, expecting that during checkout, the group pricing order total module will calculate the discount and apply the discount. And although the table has been modified, the group pricing module is never called during guest checkout. The discount is applied to normal logged in customers in the group. Thoughts?
Thanks!
Dave
Last edited by Dave224; 10 Jul 2024 at 04:10 PM.
What notification is the observer watching? I'll note that doing that on-customer update to the guest customer's database record could wind up giving the discount to the "wrong" person.
You might be better off adding a notification to ot_group_pricing's calculate_deductions method (in the check for guest-checkout, towards the top) and simply override the returned array there.
The notifier I'm using is NOTIFIER_CART_GET_PRODUCTS_START with checks on presence of $_SESSION['opc'], $_SESSION['opc']->isGuestCheckout() === true, and $_SESSION['opc']->getAddressLabelFields for the guest billing address. All this to get the first notifier occurrence after the guest's name and address is entered. This is followed by checks on the name and address against a separate table of customers who get discounts. Then the guest customer entry in table customers is updated with the guests pricing group. Finally, there's some code to set a $_SESSION variable to check to prevent repeating the processing for subsequent notifications because I couldn't get the detach notifier method to work. If the guest does not get a discount, the guest entry in table customers is returned to it's default. Not the easiest notifier, but it's the only one I could find to work with.
I think I see what you're suggesting. Basically, set the guest entry in the customer table to any pricing group so that ot_group_pricing calculates the discount, followed by checks there to see if the discount is valid for the current customer or guest and override if not valid. I would still have to eliminate the check on zen_in_guest_checkout() in method process in ot_group_pricing. Am I correct in understanding your suggestion?
Dave
What I'm suggesting is to add a notification in /includes/modules/order_total/ot_group_pricing.php's calculate_deductions method:
Your observer would watch for that notification and, if the 'order_total' isn't 0 and zen_in_guest_checkout() returns (bool)true, would check for the guest customer that you're looking to provide the deduction for and 'fill in' the $od_amount array with the discount information.Code:if ($order_total == 0 || !zen_is_logged_in() || zen_in_guest_checkout()) { global $zco_notifier; $zco_notifier->notify('NOTIFY_OT_GROUP_PRICING_DEDUCTION_OVERRIDE', ['order_total' => $order_total], $od_amount); return $od_amount; }
Got it. Thanks Cindy!
Dave
php 8.1. zc 1.58a
I received the following intermittent warning over the weekend. It is my first time to receive this warning.
The lines near line 434 is the following:PHP Code:
[21-Jul-2024 22:04:59 America/New_York] Request URI: /ajax.php?act=ajaxOnePageCheckout&method=updatePaymentMethod, IP address: xxxx, Language id 1
#0 /includes/classes/ajax/zcAjaxOnePageCheckout.php(435): zen_debug_error_handler()
#1 /includes/classes/ajax/zcAjaxOnePageCheckout.php(370): zcAjaxOnePageCheckout->createOrderTotalHtml()
#2 /ajax.php(85): zcAjaxOnePageCheckout->updatePaymentMethod()
--> PHP Warning: Undefined array key "shipping" in /includes/classes/ajax/zcAjaxOnePageCheckout.php on line 434.
PHP Code:
$checkout_one->debug_message(
"Returning:\n" .
json_encode($order->info, JSON_PRETTY_PRINT) . "\n" .
json_encode($_SESSION['shipping']) . "\n" .
($_SESSION['payment'] ?? '[not set]'),
false,
'zcAjaxOnePageCheckout::createOrderTotalHtml'
);
Thanks for the report; GitHub issue created: https://github.com/lat9/one_page_checkout/issues/418
Bookmarks