Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send emails customers who have ordered products in the list #1169

Closed
MNShop opened this issue Jan 25, 2014 · 2 comments
Closed

Send emails customers who have ordered products in the list #1169

MNShop opened this issue Jan 25, 2014 · 2 comments

Comments

@MNShop
Copy link

MNShop commented Jan 25, 2014

Today I had to sent an email to customers who had purchased one product. Guess what happened? The same email was sent 488 times to each customer (488 customers). My luck was that I stopped the process and email was sent only 14 times. How cool is to open your inbox and to find same email received hundreds of times? No so cool. Gmail thinks the same and blacklisted my website IP. Who's going to help me to remove my IP from blacklist now?

Anyway, the problem was on "admin/model/sale/order.php" and can be fixed by replacing this function:

public function getEmailsByProductsOrdered($products, $start, $end) {
        $implode = array();

        foreach ($products as $product_id) {
            $implode[] = "op.product_id = '" . $product_id . "'";
        }

        $query = $this->db->query("SELECT DISTINCT email FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "order_product op ON (o.order_id = op.order_id) WHERE (" . implode(" OR ", $implode) . ") AND o.order_status_id <> '0'");

        return $query->rows;
    }

with this function

public function getEmailsByProductsOrdered($products, $start, $end) {
        $implode = array();

        foreach ($products as $product_id) {
            $implode[] = "op.product_id = '" . $product_id . "'";
        }

        if(!empty($start) && !empty($end)){
            $limit = " LIMIT ".$start.",".$end;
        }

        $query = $this->db->query("SELECT DISTINCT email FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "order_product op ON (o.order_id = op.order_id) WHERE (" . implode(" OR ", $implode) . ") AND o.order_status_id <> '0'".$limit);

        return $query->rows;
    }
@danielkerr
Copy link
Member

not sure which version you are using but opencart has this to stop this happening:

    $query = $this->db->query("SELECT DISTINCT email FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "order_product op ON (o.order_id = op.order_id) WHERE (" . implode(" OR ", $implode) . ") AND o.order_status_id <> '0' LIMIT " . (int)$start . "," . (int)$end); 

@MNShop
Copy link
Author

MNShop commented Jan 27, 2014

I have v1.5.2.1 but maybe you have to take a look again at your own script, because this is what I found on v1.5.6.1, at the file "admin/model/sale/order.php", downloaded from opencart.com, more exactly take a look at lines 782 - 792 and see if everything seems to be ok:

    public function getEmailsByProductsOrdered($products, $start, $end) {
        $implode = array();

        foreach ($products as $product_id) {
            $implode[] = "op.product_id = '" . $product_id . "'";
        }

        $query = $this->db->query("SELECT DISTINCT email FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "order_product op ON (o.order_id = op.order_id) WHERE (" . implode(" OR ", $implode) . ") AND o.order_status_id <> '0'");

        return $query->rows;
    }

Also, on the same file (in v1.5.6.1), next function is this:

    public function getTotalEmailsByProductsOrdered($products) {
        $implode = array();

        foreach ($products as $product_id) {
            $implode[] = "op.product_id = '" . $product_id . "'";
        }

        $query = $this->db->query("SELECT DISTINCT email FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "order_product op ON (o.order_id = op.order_id) WHERE (" . implode(" OR ", $implode) . ") AND o.order_status_id <> '0' LIMIT " . $start . "," . $end);   

        return $query->row['total'];
    }   

I see 2 wrong functions here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants