You have a comma spare in your $orderQuery
just before the closing )
:
...
`shipping_address_country_id`,
)
VALUES (:order_id, :order_number, ....
Than one comma needs to be removed:
$orderQuery = "insert into `neonandmore_timeclock`.`nam_orders` (
`order_id` ,
`order_number` ,
`order_type` ,
`customer_id` ,
`sugarcrm_qms_id` ,
`date_created` ,
`date_modified` ,
`order_status` ,
`total_item_count` ,
`order_shipping_price` ,
`order_tax_price` ,
`order_items_price` ,
`order_grand_total_price` ,
`order_shipping_tracking` ,
`order_shipping_ship_date` ,
`order_notes`,
`billing_address_firstname`,
`billing_address_lastname`,
`billing_address_telephone`,
`billing_address_email`,
`billing_address_street`,
`billing_address_city`,
`billing_address_region`,
`billing_address_postcode`,
`billing_address_country_id`,
`shipping_address_firstname`,
`shipping_address_lastname`,
`shipping_address_telephone`,
`shipping_address_email`,
`shipping_address_street`,
`shipping_address_city`,
`shipping_address_region`,
`shipping_address_postcode`,
`shipping_address_country_id`
)
VALUES (:order_id, :order_number, :order_type, :customer_id, :sugarcrm_qms_id, :date_created, :date_modified, :order_status, :total_item_count, :order_shipping_price, :order_tax_price, :order_items_price, :order_grand_total_price, :order_shipping_tracking, :order_shipping_ship_date, :order_notes, :billing_address_firstname, :billing_address_lastname, :billing_address_telephone, :billing_address_email, :billing_address_street, :billing_address_city, :billing_address_region, :billing_address_postcode, :billing_address_country_id, :shipping_address_firstname, :shipping_address_lastname, :shipping_address_telephone, :shipping_address_email, :shipping_address_street, :shipping_address_city, :shipping_address_region, :shipping_address_postcode, :shipping_address_country_id)";
Why don't you just use the following:
Mage::getSingleton('catalog/product')->getIdBySku($productSku);
You can also get multiple products from a collection:
$collection = Mage::getSingleton('catalog/product')->getCollection();
$collection->addAttributeToFilter('sku', array('in' => array('sku1', 'sku2', ...)));
foreach ($collection as $product) {
echo $product->getId();
}
If you want to keep the SQL approach then use something like this:
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_write');
$productTable = $resource->getTableName('catalog/product');
$qry = $readConnection->select()->from($productTable)->where('sku=?', $productSku);
$rows = $readConnection->fetchAll($qry);
foreach ($rows as $row) {
...
}
This is just an example, so fix it with your logic.
For escape you can also use:
$readConnection->quote($myValueToEscape)
BUt you should not directly type SQL. Starting from Magento 1.6 they completely isolated the SQL layer, so you should only use the PDO calls.
Best Answer
If you guys are trying to save an attribute to product through observer "catalog_product_save_after", then this can be help:
https://webkul.com/blog/mass-update-products-attribute-magento-2/