Post by shahab7073 » Sun Feb 12, 2023 6:32 am

hello dear friends , i wanted to send sms to manufacturer/s on confirmed order,
first added a column to table manufacturer called telephone and edit manufacturer model and now i can set number for each manufacturer, then i edited the catalog/checkout/order.php and add the following codes:

Code: Select all

$product_info_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product` WHERE product_id = '" . (int)$product['product_id'] . "'");
$order_product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
$manufacturer_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "manufacturer` WHERE manufacturer_id = '" . (int)$pp_query->row['manufacturer_id'] . "'");

Code: Select all

$this->load->model('catalog/manufacturer');
$manufacturer = $this->model_catalog_manufacturer->getManufacturer($product['manufacturer_id']);
if (isset($data['manufacturer'])) {
foreach ($data['manufacturer'] as $manufacturer) {
		$this->db->query("UPDATE " . DB_PREFIX . "manufacturer SET manufacturer_id = '" . (int)$manufacturer_id . "', name = '" . $this->db->escape($manufacturer['name']) . "', telephone = '" . $this->db->escape($manufacturer['telephone']));} 
}

Code: Select all

foreach ($order_product_query->rows as $result) {
		$pro_name = $result['name'];  
		$pro_quantity = $result['quantity']; 
	}
foreach ($manufacturer_query->rows as $result) {
		$manufacturer_name = $result['name'];  
		$manufacturer_number = $result['telephone']; 
	}
$pattern_code = "snuvhlo2nl5440q";
$input_data = array(
        "name" => $manufacturer_name,
        "order_id" => $order_id,
        "status" => $manufacturer_number,
	);
 $username = "";
$password = '';
$from = "";
$to = array($manufacturer_query->row['telephone']);
$url = "https://webservice.com/patterns/pattern?username=" . $username . "&password=" . urlencode($password) . "&from=".$from."&to=" . json_encode($to) . "&input_data=" . urlencode(json_encode($input_data)) . "&pattern_code=$pattern_code";
            $handler = curl_init($url);
            curl_setopt($handler, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($handler, CURLOPT_POSTFIELDS, $input_data);
            curl_setopt($handler, CURLOPT_RETURNTRANSFER, true);
            $response = curl_exec($handler);
            echo $response;
}
else {
      echo "nothing else";                 
}			
				
				
but i get error emty manufacturer number error it means it didn't get the order manufacturer/s number.
can somebody help me in this?

Newbie

Posts

Joined
Thu Jan 03, 2019 11:55 am

Post by SohBH » Sun Feb 12, 2023 6:19 pm

Hi where exactly did you add the code?
Each order have multiple products from multiple manufacturers, so all manufacturers receive sms?

Code: Select all

$this->load->model('catalog/manufacturer');
$manufacturers = $this->model_catalog_manufacturer->getManufacturer($product['manufacturer_id']);
if (is_array($manufacturers) || is_object($manufacturers)) {
foreach ($manufacturers as $manufacturer) {
		This query is wrong 
}
This is to update telephone when edit manufacturer? Under what condition do you want to run the query

View all extensions | Request custom work | Pricing | Contact Me


User avatar
Active Member

Posts

Joined
Mon Nov 02, 2020 12:01 am
Location - Malaysia

Post by shahab7073 » Mon Feb 13, 2023 5:48 am

SohBH wrote:
Sun Feb 12, 2023 6:19 pm
Hi where exactly did you add the code?
Each order have multiple products from multiple manufacturers, so all manufacturers receive sms?

Code: Select all

$this->load->model('catalog/manufacturer');
$manufacturers = $this->model_catalog_manufacturer->getManufacturer($product['manufacturer_id']);
if (is_array($manufacturers) || is_object($manufacturers)) {
foreach ($manufacturers as $manufacturer) {
		This query is wrong 
}
This is to update telephone when edit manufacturer? Under what condition do you want to run the query
first of all thank you for your answer that would help
i've added all of these code in catalog/model/checkout/order.php
yes i want all the manufacturers from the order receive the sms, is there any way to send every manufacturer only their product name in sms ? ex : the order had 3 product with 3 different manufacturer, each one of manufacturer only receive sms with text of their product only
no i don't want to update the manufacturer i just want to grab manufacturer phone numbers and name in order.php for order products i've tested inser query also
is there any extra column needed in database ?

Newbie

Posts

Joined
Thu Jan 03, 2019 11:55 am

Post by shahab7073 » Wed Feb 15, 2023 10:42 pm

up

Newbie

Posts

Joined
Thu Jan 03, 2019 11:55 am

Post by SohBH » Thu Feb 16, 2023 5:47 pm

shahab7073 wrote:
Mon Feb 13, 2023 5:48 am
is there any extra column needed in database ?
In phpmyadmin, oc_manufacturer table

Code: Select all

ALTER TABLE `oc_manufacturer` ADD `telephone` varchar(32) NOT NULL;
Update each manufacturer with their telephone

catalog/model/checkout/order.php
public function getProducts

Code: Select all

$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_product` op 
LEFT JOIN `" . DB_PREFIX . "product` p 
ON (op.`product_id` = p.`product_id`) 
LEFT JOIN `" . DB_PREFIX . "manufacturer` m 
ON (p.`manufacturer_id` = m.`manufacturer_id`) 
WHERE `order_id` = '" . (int)$order_id . "'");

View all extensions | Request custom work | Pricing | Contact Me


User avatar
Active Member

Posts

Joined
Mon Nov 02, 2020 12:01 am
Location - Malaysia

Post by shahab7073 » Fri Feb 17, 2023 7:40 pm

first of all thank you so much, you helped me understand what's happening
i've create a new public function called getproductsmanufacturer() as you said and changed the query for the function to this :
catalog/model/checkout/order.php

Code: Select all

public function getproductsmanufacturer($order_id) {

$query = $this->db->query("SELECT op.*, p.*, GROUP_CONCAT(DISTINCT m.`name`) as manufacturer_names, GROUP_CONCAT(DISTINCT m.`telephone`) as manufacturer_telephones, GROUP_CONCAT(DISTINCT m.`manufacturer_id`) as manufacturer_ids FROM `" . DB_PREFIX . "order_product` op LEFT JOIN `" . DB_PREFIX . "product` p ON (op.`product_id` = p.`product_id`) LEFT JOIN `" . DB_PREFIX . "manufacturer` m ON (p.`manufacturer_id` = m.`manufacturer_id`) WHERE `order_id` = '" . (int)$order_id . "'");

$results = array();
        foreach ($query->rows as $row) {
        $manufacturer_names = explode(",", $row['manufacturer_names']);
        $manufacturer_telephones = explode(",", $row['manufacturer_telephones']);
        $manufacturer_ids = explode(",", $row['manufacturer_ids']);
        $product_id = $row['product_id'];
        $product_name = $row['name'];

        for ($i = 0; $i < count($manufacturer_names); $i++) {
            $manufacturer_name = $manufacturer_names[$i];
            $manufacturer_telephone = $manufacturer_telephones[$i];
            $manufacturer_id = $manufacturer_ids[$i];

            $results[] = array(
                'manufacturer_name' => $manufacturer_name,
                'manufacturer_telephone' => $manufacturer_telephone,
                'manufacturer_id' => $manufacturer_id,
                'order_id' => $order_id,
                'product_id' => $product_id,
                'product_name' => $product_name,
            );
        }
    }
     return $results;
}
and added this code to catalog/controller/checkout/success.php

Code: Select all

$ordered_products = $this->model_checkout_order->getproductsmanufacturer($order_id);
$data['ordered_products'] = $ordered_products;
foreach ($ordered_products as $ordered_product) {
    $manufacturer_name = $ordered_product['manufacturer_name'];
    $manufacturer_telephone = $ordered_product['manufacturer_telephone'];
    $product_name = $ordered_product['product_name'];
    $manufacturer_id = $ordered_product['manufacturer_id'];
}

    $pattern_code = "11hi8uiyoa1bq8w";
    $input_data = array(
        "tamin" => $manufacturer_name,
        "order_id" => $order_id,
        "product" => $product_name,
	);
    $username = "username";
    $password = 'password';
    $from = "+983000505";
    $to = array($manufacturer_telephone);
    $url = "https://ippanel.com/patterns/pattern?username=" . $username . "&password=" . urlencode($password) . "&from=".$from."&to=" . json_encode($to) . "&input_data=" . urlencode(json_encode($input_data)) . "&pattern_code=$pattern_code";
            $handler = curl_init($url);
            curl_setopt($handler, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($handler, CURLOPT_POSTFIELDS, $input_data);
            curl_setopt($handler, CURLOPT_RETURNTRANSFER, true);
            $response = curl_exec($handler);
            echo $response;
and now i can get sms of order for manufacturer. but sms sended to first/one manufacturer only and in product name only shows the one manufacturer product name that is ok , but i wanted to send sms to all manufacturer in order products and only send them their product name like now only for all the manufacturer of order.

did make an array for manufacturers and changed the query and Separated manufacturer telephones and names with a comma but it won't get all manufacturer . i've tested so many time and none of my test workes still pass only one manufacturer telephone and name.
i don't know where my problem is :-(

Newbie

Posts

Joined
Thu Jan 03, 2019 11:55 am

Post by SohBH » Sat Feb 18, 2023 2:18 pm

If you are still unable to resolve the issue, you can contact me to discuss your project in detail.
I can revise it to send sms to all manufacturers.

View all extensions | Request custom work | Pricing | Contact Me


User avatar
Active Member

Posts

Joined
Mon Nov 02, 2020 12:01 am
Location - Malaysia

Post by pprmkr » Sat Feb 18, 2023 5:32 pm

In catalog/model/checkout/order.php add :

Code: Select all

	public function checkDatabaseonManufacturerPhone() {
		$manufacturerphone_altered = $this->db->query("SHOW COLUMNS FROM `".DB_PREFIX."manufacturer` LIKE 'telephone';");
		if ( !$manufacturerphone_altered->row ) {
			$this->db->query("ALTER TABLE `".DB_PREFIX."manufacturer` ADD `telephone` varchar(32) NOT NULL DEFAULT '0' AFTER `image`;");	
		}
		
	}
	public function getOrderManufacturer($order_product_id) {
		// first check if telephone exists
		$this->checkDatabaseonManufacturerPhone();
		
		$manufacturer_query = $this->db->query("SELECT p.product_id as product_id, m.manufacturer_id as manufacturer_id, m.name AS name, m.telephone as telephone FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$order_product_id . "'");

		if ($manufacturer_query->rows) {
			return $manufacturer_query->row;
		} else {
			return false;
		}
	}
In catalog/controller/mail/order.php:
Before the second:

Code: Select all

foreach ($order_products as $order_product) {
Add:

Code: Select all

$manufacturers_data = array();
Afterthe second:

Code: Select all

foreach ($order_products as $order_product) {
Add:

Code: Select all

			$orderproduct_manufacturer = $this->model_checkout_order->getOrderManufacturer($order_product['product_id']);
			
			if ($orderproduct_manufacturer) {
				if (!array_key_exists($orderproduct_manufacturer['manufacturer_id'], $manufacturers_data)) {
					$manufacturers_data[$orderproduct_manufacturer['manufacturer_id']] = array(
						'manufacturer_id'	=> $orderproduct_manufacturer['manufacturer_id'],
						'name'				=> $orderproduct_manufacturer['name'],
						'telephone' 		=> $orderproduct_manufacturer['telephone']
					);
				}				
				
				$manufacturers_data[$orderproduct_manufacturer['manufacturer_id']]['products'][] = array(
					'product_id' =>  $order_product['product_id'],
					'name'			=> $order_product['name'],
					'model'			=> $order_product['model'],
					'quantity'		=> $order_product['quantity']
				);
			}
After the first

Code: Select all

$mail->send();
Add:

Code: Select all

		$this->log->write($manufacturers_data);
		foreach ($manufacturers_data as $manufacturer) {
			$ordered_products = '';
			
			foreach ($manufacturer['products'] as $ordered_product) {
				$ordered_products .= $ordered_product['quantity'] . ' x ' .  $ordered_product['product_id'] . ' ' . $ordered_product['name'] . '-' . $ordered_product['model'] . "\n";
			}
			
			$this->log->write('To ' . $manufacturer['name']);
			$this->log->write('Phone ' . $manufacturer['telephone']);
			$this->log->write('Products ' . $ordered_products);
			 
			// SMS code here
		}
Note: log->write only for testing. Remove lines after finishing SMS code

User avatar
Active Member

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands

Post by shahab7073 » Mon Mar 13, 2023 12:04 pm

pprmkr wrote:
Sat Feb 18, 2023 5:32 pm
In catalog/model/checkout/order.php add :
thank you so much i was done it in a very hard way from controller , but this is a very beautiful and clean code i'm using it right now. <3

Newbie

Posts

Joined
Thu Jan 03, 2019 11:55 am
Who is online

Users browsing this forum: Baidu [Spider] and 45 guests