Skip to content
This repository has been archived by the owner on Oct 17, 2020. It is now read-only.

Commit

Permalink
Prevent problem with product name having quote
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainraye committed Jan 8, 2016
1 parent 4e2ecf1 commit acbe977
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
35 changes: 16 additions & 19 deletions src/app/code/community/Diglin/Facebook/Block/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
*/
class Diglin_Facebook_Block_Tag extends Mage_Core_Block_Template
{
/**
* @var array
*/
protected $_tags = array();

/**
Expand Down Expand Up @@ -41,35 +44,23 @@ public function getTags()

/**
* @param $handle
* @return $this
*/
public function getViewContentTag($handle)
{
if (strpos('catalog_product_view', $handle) !== false) {
/* @var $this Mage_Catalog_Model_Product */
/* @var $product Mage_Catalog_Model_Product */
$product = Mage::registry('product');

$this->_tags[] = $this->getFBHelper()->getTag('ViewContent', $product);

// $category = null;
// if ($product->getCategory()) {
// $category = Mage::helper('core')->quoteEscape($product->getCategory()->getName());
// }
//
// $productName = Mage::helper('core')->quoteEscape($product->getName());
//
// $this->_tags[] = "fbq('track', 'ViewContent', {"
// . "content_name : '{$productName}', "
// . "content_category : '{$category}', "
// . "content_type : 'product', "
// . "value : " . round($product->getPrice(), 2) . ", "
// . "currency : '{$this->getCurrency()}', "
// . "content_ids : ['{$this->getFBHelper()->getProductId($product)}']"
// . "});";
}

return $this;
}

/**
* @param $handle
* @return $this
*/
public function getSearchTag($handle)
{
Expand All @@ -80,10 +71,12 @@ public function getSearchTag($handle)

$this->_tags[] = "fbq('track', 'Search', {value : '" . $query->getQueryText() . "'});";
}
return $this;
}

/**
* @param $handle
* @return $this
*/
public function getInitiateCheckoutTag($handle)
{
Expand All @@ -97,10 +90,13 @@ public function getInitiateCheckoutTag($handle)
$numItems = count($quote->getAllItems());
$this->_tags[] = "fbq('track', 'InitiateCheckout', {num_items : '{$numItems}'});";
}

return $this;
}

/**
* @param $handle
* @return $this
*/
public function getPurchaseTag($handle)
{
Expand All @@ -114,23 +110,24 @@ public function getPurchaseTag($handle)
}

$order = Mage::getModel('sales/order')->load($session->getLastOrderId());

if (!$order->getId()) {
return;
}

/* @var $item Mage_Sales_Model_Order_Item */
foreach ($order->getAllItems() as $item) {
$productId = ($this->getFBHelper()->getProductIdType($order->getStore()) == 'sku') ? $item->getSku() : $item->getProductId();
$name = Mage::helper('diglin_facebook')->escapeHtml($item->getName());

$this->_tags[] = "fbq('track', 'Purchase', { "
. "value: '". round($item->getRowTotalInclTax(), 2) ."', "
. "currency: '{$order->getOrderCurrencyCode()}', "
. "content_name : '{$item->getName()}', "
. "content_name : '{$name}', "
. "content_type : 'product', "
. "content_ids : ['{$productId}']});";
}
}
return $this;
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/app/code/community/Diglin/Facebook/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ public function getTag($type, Mage_Catalog_Model_Product $product, $functionWrap

$category = null;
if ($product->getCategory()) {
$category = Mage::helper('core')->quoteEscape($product->getCategory()->getName());
$category = $this->escapeHtml($product->getCategory()->getName());
}

$productName = str_replace("'"," ", $product->getName());
// $productName = Mage::helper('core')->quoteEscape($product->getName());
$productName = $this->escapeHtml($product->getName());
$price = round($product->getPrice(), 2);

$tag = <<<HTML
Expand Down

0 comments on commit acbe977

Please sign in to comment.