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

Product name not escaped in ProductDataLayer #1

Open
fabrice-dresscodes opened this issue Apr 24, 2024 · 1 comment
Open

Product name not escaped in ProductDataLayer #1

fabrice-dresscodes opened this issue Apr 24, 2024 · 1 comment

Comments

@fabrice-dresscodes
Copy link

fabrice-dresscodes commented Apr 24, 2024

If the product's name has apostrophs in the name, there is an issue with de javascript.

That's why I had to rewrite the ProductDataLayer to add the fuction htmlspecialchars

`

namespace XXXXX\Design\Block\Rewrite;

use KingfisherDirect\GoogleTagManager\Block\DataLayer;

class ProductDataLayer extends \KingfisherDirect\GoogleTagManager\Block\ProductDataLayer
{
public function configureDataLayer(DataLayer $dataLayer)
{
$product = $this->getProduct();

    if (!$product) {
        return null;
    }

    $dataLayer->push(['ecommerce' => null]);
    $dataLayer->push([
        'ecommerce' => [
            'detail' => [
                'products' => [
                    [
                        'id' => $product->getSku(),
                        'name' => htmlspecialchars($product->getName(),ENT_QUOTES),
                        'price' => $this->getProductPrice($product),
                    ]
                ]
            ]
        ]
    ]);
}

}
`

@lumnn
Copy link
Contributor

lumnn commented Apr 24, 2024

Do you mind sending a PR for that please?

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