Hello, I would like to make it so when an order is placed from a specific product it does something Zencart cant.
What file/file folder should I put this file in so when a product is purchased it runs this file?
Hello, I would like to make it so when an order is placed from a specific product it does something Zencart cant.
What file/file folder should I put this file in so when a product is purchased it runs this file?
Can you be more specific about what you're actually doing? What's needing to run and why?
Also, "when" should this program run? While the order details are being prepared so that some output can be included in the order? or after the emails are sent? or after the customer clicks a button on the checkout_success page? etc
Does it need to run instantly? Or can it be queued to run periodically such as checking every 5 minutes to see if it needs to be run.
Does it require any inputs from the order information? Which details does it require?
And, is it possible that this program might generate errors? If so, how should those be handled?
.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole
Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.
I guess this is a duplicate of your other post? Need to send emails to supplier per product sale
.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole
Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.
I'm looking to do this when the order is placed at about the same time the order.php file is run. But I have no idea where to put my own code so that it 1. does not conflict with the existing code 2. but also will execute everything I need it too.
So yes kinda like my last post but I would just like to know where to put my code without messing with core files.
It's not like you can just place a file somewhere and that's it... IMHO, the best way to do this would be to create an observer on NOTIFY_HEADER_END_CHECKOUT_PROCESS and then have it go through the list of purchased products, and if the product is found in that order, trigger your function to run whatever you're running.
There are other possible approaches, but I believe this would be best and least obtrusive, and doesn't require modifying any core or template files.
Another method that comes to mind is to create a new file in extra_functions/ directory, start it with something likeand then figure out how to go through the list of purchased products and trigger your code if required product found. But I'd still go with the observer, it's actually simpler...Code:<?php function doSomethingZenCartCant { global $current_page_base; if($current_page_base == 'checkout_success') { // your code here } }
I will look into trying to create an observer for what I need to do, that might be the best option for what I am doing. Thank you!
Without knowing more about your product setup or what you're aiming to do for each, here's a possible basic structure for an Observer class:
PHP Code:
<?php
class send_supplier_emails_after_order_observer extends base
{
protected $order_id;
public function __construct()
{
$this->attach($this, array(
'NOTIFY_HEADER_END_CHECKOUT_PROCESS',
// 'NOTIFY_CHECKOUT_PROCESS_BEFORE_CART_RESET',
));
}
// NOTIFY_HEADER_END_CHECKOUT_PROCESS
public function updateNotifyHeaderEndCheckoutProcess(&$class, $eventID, $order_id)
{
// prior to v1.5.8 the order number must be retrieved this way:
if (empty($order_id)) {
global $insert_id;
if (!empty($insert_id)) {
$order_id = $insert_id;
}
}
// abort if no order number
if (empty($order_id)) return;
$this->order_id = $order_id;
$order = new Order($this->order_id);
$this->processProducts($order->products);
}
// NOTIFY_ORDER_DURING_CREATE_ADD_PRODUCTS
public function updateNotifyCheckoutProcessBeforeCartReset(&$class, $eventID, $order_id)
{
// abort if no order number
if (empty($order_id)) return;
$this->order_id = $order_id;
$order = new Order($this->order_id);
$this->processProducts($order->products);
}
/**
* @param array $products all products in the order
* The indices of each product come from https://github.com/zencart/zencart/blob/7c324c2dfabd35b53eb543fae46efabf26a6a929/includes/classes/order.php#L181-L201
* and the sub-indices of each products' [attributes] array come from https://github.com/zencart/zencart/blob/7c324c2dfabd35b53eb543fae46efabf26a6a929/includes/classes/order.php#L217-L223
*
*/
protected function processProducts($products)
{
foreach ($products as $product) {
// take action based on product ID:
switch ($product['id']) {
case '333':
// do something related to product #333
break;
case '444':
// do something related to product #444
break;
}
}
}
}
.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole
Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.
This should work for what I need to do. I should be able to do what I need to from here thanks for the help!
Turns out I am still a bit confused.. Here is a function I want to run a copy of the admin email in this file, how can I achieve this because when the email fires it only gives the info defined in the file.
So how can I pull the parameters set in the order.php file in this file so when the email is sent it has the correct info? As you may notice I did remove some of the things I don't want to be sent in this copy of the admin email.PHP Code:
public function emailOrder($zf_insert_id = null)
{
if ($zf_insert_id === null) $zf_insert_id = $this->orderId;
$extra_info = email_collect_extra_info('', '', $this->customer['firstname'] . ' ' . $this->customer['lastname'], $this->customer['email_address'], $this->customer['telephone']);
$html_msg['EXTRA_INFO'] = $extra_info['HTML'];
// Add extra heading stuff via observer class
$this->extra_header_text = '';
$this->notify('NOTIFY_ORDER_INVOICE_CONTENT_FOR_ADDITIONAL_EMAILS', $zf_insert_id, $email_order, $html_msg);
$email_order = $this->extra_header_text . $email_order;
$html_msg['EMAIL_TEXT_HEADER'] = nl2br($this->extra_header_text) . $html_msg['EMAIL_TEXT_HEADER'];
zen_mail(
'',
'the email',
SEND_EXTRA_NEW_ORDERS_EMAILS_TO_SUBJECT . ' ' . EMAIL_TEXT_SUBJECT . EMAIL_ORDER_NUMBER_SUBJECT . $zf_insert_id,
$email_order . $extra_info['TEXT'],
STORE_NAME,
EMAIL_FROM,
$html_msg,
'checkout_extra',
$this->attachArray,
$this->customer['firstname'] . ' ' . $this->customer['lastname'],
$this->customer['email_address']
);
}
Last edited by Famine_1; 8 Jan 2021 at 06:17 PM.
Using my code sample as a base, the $order variable built in both of those updateXYZ functions has access to all the data inside the order (comes from the order.php class).
Inside those functions you can refer to that data via "$order->foo" the same as the order class would refer to "$this->foo"
.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole
Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.
Bookmarks