Osclass Support Forums

Osclass plugin support => Osclass Pay Plugin => Topic started by: Tango on January 05, 2022, 12:22:53 PM

Title: New Order Alert
Post by: Tango on January 05, 2022, 12:22:53 PM
At the moment, our eCommerce system is missing an alert system for when a seller has orders that need processing.
Many times sellers will forget to check if they have new or old orders that need processing.

To fix this, we need to a nagging alert that appears every time you refresh the site, if there are orders with Processing status.
(https://i.ibb.co/9s6C90d/notification.png)

Logic:

This would help A LOT! ;D

Thanks!
Title: Re: New Order Alert
Post by: MB Themes on January 05, 2022, 12:50:18 PM
@Tango
Thanks for feedback ;)
Title: Re: New Order Alert
Post by: BTN Digital Media on January 09, 2022, 07:10:17 AM
Great  :)
Title: Re: New Order Alert
Post by: Tango on September 27, 2022, 01:36:10 PM
@Michal
I'm trying to implement this by adding the following in osclas_pay/functions.php:
Code: [Select]
// FLASH MESSAGE FOR ORDERS THAT NEED PROCESSING
function osp_new_orders_notification() {
  if(osc_is_web_user_logged_in()) {
    $sellers = array_filter(explode(',', osp_param('seller_users')));
    $is_seller = false;
    if(in_array(osc_logged_user_id(), $sellers) || osp_param('seller_all') == 1) {
      $is_seller = true;
    }

    if($is_seller && osp_param('enable_user_management') == 1) {
      $params = Params::getParamsAsArray();
      $order_items = isset($order['order_items']) ? $order['order_items'] : 0;

      if( (isset($order_items['i_status']) == OSP_ORDER_PROCESSING) > 0 ) {
        osc_add_flash_warning_message(__('You have orders that need processing. <a href="' . osc_route_url('osp-manager') . '">Click here</a> to fulfill them.', 'osclass_pay'));
      }
    }
  }
}

osc_add_hook('header', 'osp_new_orders_notification');

However, the flash message always appears, for all users.
The idea is to have it appear only for sellers that have orders with the status Processing.

Any feedback?
Thanks!
Title: Re: New Order Alert
Post by: MB Themes on September 27, 2022, 01:53:00 PM
@Tango
I do not see source for this:
Code: [Select]
      $order_items = isset($order['order_items']) ? $order['order_items'] : 0;
Title: Re: New Order Alert
Post by: Tango on September 27, 2022, 02:48:20 PM
Yeah, tried this but still nothing:
Code: [Select]
// FLASH MESSAGE FOR ORDERS THAT NEED PROCESSING
function osp_new_orders_notification() {
  if(osc_is_web_user_logged_in()) {
    $is_seller = osp_user_is_seller(osc_logged_user_id());

    if($is_seller && osp_param('enable_user_management') == 1) {
      $params = Params::getParamsAsArray();
      $orders = ModelOSP::newInstance()->getOrdersWithItems($params);

      if(is_array($orders) && count($orders) > 0) {
        if($orders['i_status'] == OSP_ORDER_PROCESSING) {
          osc_add_flash_warning_message(__('You have orders that need processing. <a href="' . osc_route_url('osp-manager') . '">Click here</a> to fulfill them.', 'osclass_pay'));
        }
      }
    }
  }
}

osc_add_hook('header', 'osp_new_orders_notification');

I give up, my head hurts :'(
Title: Re: New Order Alert
Post by: MB Themes on September 27, 2022, 06:27:47 PM
I think you should just get orders for specific user and check if there is some in processing, or get only processing orders.
Do not have time to check into code now.
Title: Re: New Order Alert
Post by: Tango on September 28, 2022, 11:41:32 AM
I think you should just get orders for specific user and check if there is some in processing, or get only processing orders.
Yeah, I got the user sales where the order status is also present, but still nothing.
There's something fishy going on, as this should be a fairly simple function: check if the user is seller > check if he has orders > check if those orders have PROCESSING status > if true, output the message.

Code: [Select]
// FLASH MESSAGE FOR ORDERS THAT NEED PROCESSING
function osp_new_orders_notification() {
  if(osc_is_web_user_logged_in()) {
    $is_seller = osp_user_is_seller(osc_logged_user_id());

    if($is_seller && osp_param('enable_user_management') == 1) {
      $orders = ModelOSP::newInstance()->getUserSales($is_seller);

      if(is_array($orders) && count($orders) > 0) {
        if(isset($orders['i_status']) && $orders['i_status'] == OSP_ORDER_PROCESSING) {
          osc_add_flash_warning_message(__('You have orders that need processing. <a href="' . osc_route_url('osp-manager') . '">Click here</a> to fulfill them.', 'osclass_pay'));
        }
      }
    }
  }
}

osc_add_hook('header', 'osp_new_orders_notification');
Title: Re: New Order Alert
Post by: MB Themes on September 28, 2022, 01:21:04 PM
@Tango
Shouldnt be this part:
Code: [Select]
      if(is_array($orders) && count($orders) > 0) {
        if(isset($orders['i_status']) && $orders['i_status'] == OSP_ORDER_PROCESSING) {
          osc_add_flash_warning_message(__('You have orders that need processing. <a href="' . osc_route_url('osp-manager') . '">Click here</a> to fulfill them.', 'osclass_pay'));
        }

replaced with:
Code: [Select]
      if(is_array($orders) && count($orders) > 0) {
        foreach($orders as $order) {
          if(isset($order['i_status']) && $order['i_status'] == OSP_ORDER_PROCESSING) {
            osc_add_flash_warning_message(__('You have orders that need processing. <a href="' . osc_route_url('osp-manager') . '">Click here</a> to fulfill them.', 'osclass_pay'));
            break;
          }
        }
Title: Re: New Order Alert
Post by: Tango on September 28, 2022, 02:22:34 PM
We finally have a solution (I've also added a check for seller_all, in order to prevent showing the notification for both sellers and buyers when Enable All Registered to Sell Products is active).
Maybe you can implement it in the next plugin version (don't forget to add the translation string in languages).

Code: [Select]
// FLASH MESSAGE FOR ORDERS THAT NEED PROCESSING
function osp_new_orders_notification() {
  if(osc_is_web_user_logged_in()) {
    $is_seller = osp_user_is_seller(osc_logged_user_id());

    if($is_seller && osp_param('seller_all') != 1 && osp_param('enable_user_management') == 1) {
      $orders = ModelOSP::newInstance()->getUserSales($is_seller);

      if(is_array($orders) && count($orders) > 0) {
        foreach($orders as $order) {
          if(isset($order['i_status']) && $order['i_status'] == OSP_ORDER_PROCESSING) {
            osc_add_flash_warning_message(__('You have orders that need processing. <a href="' . osc_route_url('osp-manager') . '">Click here</a> to fulfill them.', 'osclass_pay'));
            break;
          }
        }
      }
    }
  }
}

osc_add_hook('header', 'osp_new_orders_notification');

Thanks a lot Michal! :P
Title: Re: New Order Alert
Post by: Fabio Massaro on October 25, 2022, 09:12:16 AM
Hi @Tango I have been following you for some time and I like your commitment. I would like to understand (New order notice)
Title: Re: New Order Alert
Post by: Tango on October 25, 2022, 06:08:36 PM
Hi @Tango I have been following you for some time and I like your commitment. I would like to understand (New order notice)
There's nothing to understand. You got the design proposition in the first post and the implementation in the one above.

At this point, you can only pray that MB Themes finds the time to test this and implement it in the plugin.
Until then, you're on your own.

Good luck!
Title: Re: New Order Alert
Post by: Fabio Massaro on October 25, 2022, 08:31:49 PM
Hi @Tango I have been following you for some time and I like your commitment. I would like to understand (New order notice)
There's nothing to understand. You got the design proposition in the first post and the implementation in the one above.

At this point, you can only pray that MB Themes finds the time to test this and implement it in the plugin.
Until then, you're on your own.

Good luck!

I don't care it was just curiosity all here
I understand how to develop my site