diff --git a/config.xml b/config.xml index 9c69a24..1f5595f 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ salesfire - + diff --git a/salesfire.php b/salesfire.php index 68acc9d..0be383d 100644 --- a/salesfire.php +++ b/salesfire.php @@ -34,10 +34,10 @@ class Salesfire extends Module public function __construct() { - $this->name = 'salesfire'; - $this->tab = 'smart_shopping'; - $this->version = '0.2.0'; - $this->author = 'Salesfire'; + $this->name = 'salesfire'; + $this->tab = 'smart_shopping'; + $this->version = '0.2.1'; + $this->author = 'Salesfire'; $this->need_instance = 0; /** @@ -223,10 +223,14 @@ public function hookHeader() if (method_exists($this->context->controller, 'getProduct')) { $product = $this->context->controller->getProduct(); + if (! Validate::isLoadedObject($product)) { + return $display; + } + $smarty_variables['sfProduct'] = array( - 'sku' => $product->product_id, - 'name' => $product->name, - 'price' => $product->price + 'sku' => $product->id, + 'name' => $product->name, + 'price' => $product->price, ); $this->smarty->assign($smarty_variables); @@ -239,38 +243,43 @@ public function hookHeader() public function hookOrderConfirmation($params) { - if (!Configuration::get('SALESFIRE_ACTIVE')) { + if (! Configuration::get('SALESFIRE_ACTIVE')) { return; } $order = $params['order']; + + if (! Validate::isLoadedObject($order)) { + return; + } + $currency = Currency::getCurrencyInstance((int) $order->id_currency); $sfOrder = array( 'ecommerce' => array( 'purchase' => array( - 'id' => $order->id, - 'revenue' => $order->total_paid_tax_excl, - 'shipping' => $order->total_shipping, - 'tax' => $order->total_paid_tax_incl - $order->total_paid_tax_excl, + 'id' => $order->id, + 'revenue' => (int) $order->total_paid_tax_excl, + 'shipping' => (int) $order->total_shipping, + 'tax' => (int) $order->total_paid_tax_incl - (int) $order->total_paid_tax_excl, 'currency' => $currency->iso_code, - 'products' => array() - ) - ) + 'products' => array(), + ), + ), ); foreach ($order->getProducts() as $product) { $sfOrder['ecommerce']['purchase']['products'][] = array( - 'sku' => $product['product_id'], + 'sku' => $product['product_id'], 'parent_sku' => $product['product_id'], - 'name' => $product['product_name'], - 'price' => $product['total_price'], - 'currency' => $currency->iso_code + 'name' => $product['product_name'], + 'price' => (int) $product['total_price'], + 'currency' => $currency->iso_code, ); } $this->smarty->assign(array( - 'sfOrder' => $sfOrder + 'sfOrder' => $sfOrder, )); return $this->display(__FILE__, 'order-success.tpl'); diff --git a/views/templates/hook/product-views.tpl b/views/templates/hook/product-views.tpl index 63d174e..a7ed531 100644 --- a/views/templates/hook/product-views.tpl +++ b/views/templates/hook/product-views.tpl @@ -30,9 +30,9 @@ "view": { "sku": "{$sfProduct['sku']}", "name": "{$sfProduct['name']}", - "price": {$sfProduct['price']} + "price": {$sfProduct['price']}, "currency": prestashop.currency.iso_code } } }); - \ No newline at end of file +