How to send ecommerce data to datalayer in prestashop - prestashop

I am not a developer but trying to send ecommerce data to datalayer. I can't see any ecommerce data to datalayer in console. I am adding the data to order-confirmation.tpl in prestashop. below is how i am sending data
<Script type = "text / javascript">
dataLayer = ( {
'transactionId' : '{literal} {$order_id} {/literal}' ,
'transactionTotal' : {literal } { $total_a_payment } {/literal } ,
'transactionTax' : { literal } { $tax } { /literal } ,
'transactionShipping' : { literal } { $ expenses_envoice } { /literal
} ,
'transactionProducts' : [ { /literal } { foreach from = $ products
item = product name = products } { /literal }
{
'Sku' : '{literal}{$producto.id_product}{/literal}' ,
'Name' : '{literal}{$producto.name}{/literal}' ,
'Price' : { literal } { $ product . Price_wt } { /literal } ,
'Quantity' : { literal } { $ product . Quantity } { /literal }
} { Literal} {if $ smarty.foreach.productos.iteration! = $ Products
| #count} {literal}, {/ literal } { / if } { /literal }
{ Literal} {/ foreach } ] , { /literal }
'Event' : 'transactionComplete'
} )
</ Script>
{ / Literal }
anyone have experience with prestashop please help. I am using Google Tag Manager for ecommerce tracking. thanks

I had the same issue. You have to also edit file controllers/front/OrderConfirmationController.php.
Find function displayOrderConfirmation and insert something like this part of code:
$order = new Order($this->id_order);
$currency = new Currency($order->id_currency);
/* added part */
$cart = new Cart($order->id_cart);
$products = $cart->getProducts();
$this->context->smarty->assign(array(
'order_id'=> $this->id_order,
'total_a_payment'=> $order->total_paid_tax_incl,
'expenses_envoice'=> $order->total_shipping_tax_incl,
'tax'=> ($order->total_paid_tax_incl - $order->total_paid_tax_excl),
'products' => $products
));
/*end of added*/
Original source: https://www.prestashop.com/forums/topic/618328-variables-for-google-tag-manager/

Related

Validator not validating the request in Laravel 8

I am inserting the data. The data is being entering quite fine but whenever I enter a letter the entry is done but that entry is converted to '0'.
This is my controller store function:
public function store(GuidanceReportRequest $request)
{
$stats = GuidanceReport::where('user_id', $request->user_id)->whereDate('created_at', now())->count();
if ($stats > 0) {
Session::flash('warning', 'Record already exists for current date');
return redirect()->route('reports.index');
}
if ((!empty($request->call_per_day[0]) && !empty($request->transfer_per_day[0])) ||
(!empty($request->call_per_day[1]) && !empty($request->transfer_per_day[1])) || (!empty($request->call_per_day[2])
&& !empty($request->transfer_per_day[2]))
) {
foreach ($request->category as $key => $value) {
$catgeory_id = $request->category[$key];
$call_per_day = $request->call_per_day[$key];
$transfer_per_day = $request->transfer_per_day[$key];
if (!empty($catgeory_id) && !empty($call_per_day) && !empty($transfer_per_day)) {
GuidanceReport::create([
"user_id" => $request->user_id,
"categories_id" => $catgeory_id,
"call_per_day" => $call_per_day,
"transfer_per_day" => $transfer_per_day,
]);
}
}
} else {
GuidanceReport::create($request->except('category', 'call_per_day', 'transfer_per_day'));
}
Session::flash('success', 'Data Added successfully!');
return redirect()->route('reports.index');
}
This is my Validation Request code
public function rules()
{
$rules = [];
$request = $this->request;
if ($request->has('transfer_per_day')) {
if (!empty($request->transfer_per_day)) {
$rules['transfer_per_day'] = "numeric";
}
}
if ($request->has('call_per_day')) {
if (!empty($request->call_per_day)) {
$rules['call_per_day'] = "numeric";
}
}
if ($request->has('rea_sign_up')) {
if (!empty($request->rea_sign_up)) {
$rules['rea_sign_up'] = "numeric";
}
}
if ($request->has('tbd_assigned')) {
if (!empty($request->tbd_assigned)) {
$rules['tbd_assigned'] = "numeric";
}
}
if ($request->has('no_of_matches')) {
if (!empty($request->no_of_matches)) {
$rules['no_of_matches'] = "numeric";
}
}
if ($request->has('leads')) {
if (!empty($request->leads)) {
$rules['leads'] = "numeric";
}
}
if ($request->has('conversations')) {
if (!empty($request->conversations)) {
$rules['conversations'] = "numeric";
}
}
return $rules;
}
Although I check the type in which request is being sent from controller and recieved from the request validation and it is Object. So how can I solve the issue.

How to disable a graphql filter if the variable is not set?

I am working on a page with configurable filters. The graphql query looks like:
query GetPlayers(
$offset: Int
$limit: Int
$skillIds: [uuid!] = null
$playerTypeIds: [Int!] = null
$availability: Int = null
$timezones: [String!] = null
$search: String = null
) {
player(
order_by: { total_xp: desc }
offset: $offset
limit: $limit
where: {
availability_hours: { _gte: $availability }
timezone: { _in: $timezones }
player_type_id: { _in: $playerTypeIds }
Player_Skills: { Skill: { id: { _in: $skillIds } } }
_or: [
{ username: { _ilike: $search } }
{ ethereum_address: { _ilike: $search } }
]
}
) {
id
}
}
I would like the default behavior to be to return all entries. I am using Hasura 1.3.3 and null is interpreted as {} which will return all entries. The only problem is the Player_Skills: { Skill: { id: { _in: $skillIds } } } line. There is a join table with foreign keys referring to the players and skills tables, and that line will only return players who have at least one entry in that table.
Is it possible to form a query that will ignore the skills filter if $skillIds is null?

How to convert a json response to match schema (not manually)?

I'm trying to validate a schema for complex JSON. We can easily compare a schema with API response by below command
And match response == response_SCHEMA
(where "response_SCHEMA" is json schema)
For small json we can manually create:
Actual API response:
{ "id": "123", "name": "abc", "type": "Mumbai", "owner": { "name": "Mr Singh", "type": "Business", "licenseNo": "ASL8989" }
Converted the response to below - manually
{ "id": "#number", "name": "#string", "type": "#string", "owner": { "name": "#string", "type": "#string", "licenseNo": "#string" }
How to create this kind of schema automatically for a complex big json having 300-400 lines? So, we can compare it with API response with Karate.
The point of the schema design is that you can easily cut and paste an actual JSON and either use it as it is (data match, recommended) or edit it to use #string etc (schema match).
When you say 300-400 lines, most likely you mean an array of JSON. All you need to do is specify the schema of the "repeating part" and then use match each: https://github.com/intuit/karate#match-each
* def actual = [{ a: 1, b: 'x' }, { a: 2, b: 'y' }]
* def schema = { a: '#number', b: '#string' }
* match each actual == schema
The short answer is there is no automatic way to do it. Typically you never need to do more than a few lines. Maybe you can write your own custom utility.
#Mayank I also faced this issue, Unfortunately I didn't find any options.
So I created my own small JS to convert the actual JSON into JSON Schema which is compatible with Karate Fuzzy Match.
The output may look like this
enter image description here
Hope This Helps!...
function main() {
var json;
if (document.getElementById('code').value) {
try {
json = JSON.parse(document.getElementById('code').value);
document.getElementById('code').value = JSON.stringify(inputTxt, null, 2);
document.getElementById('output').value = '';
} catch (e) {
document.getElementById('output').value = e;
}
}
let outArr = {};
let output = convertJson(json, 'response', true);
ouput = Object.assign(output, outArr);
Object.keys(ouput).forEach(key => ouput[key] === "#undefined" && delete ouput[key]);
document.getElementById('output').value = JSON.stringify(output, null, 2);
function convertJson(json, keyName, isParent) {
let outA = {};
let x = {};
let y = {};
Object.keys(json).forEach(function(key) {
if (!(getJSType(json[key]) === "object") && !(getJSType(json[key]) === "array")) {
x[key] = '#' + getJSType(json[key]);
}
if (getJSType(json[key]) === "object") {
x[key] = convertJson(json[key], key, false);
}
if (getJSType(json[key]) === "array") {
x[key] = '#' + getJSType(json[key]);
// y[key + 'arr'] = getArray(json[key][0], key, false);
getArray(json[key][0], key, false);
}
})
if (isParent) {
if (Object.keys(x).length > 0) {
outA[keyName] = x;
}
if (Object.keys(y).length > 0) {
outA[keyName + 'Arr'] = y;
}
return outA;
} else {
if (Object.keys(y).length > 0 && isParent) {
return y;
}
if (Object.keys(x).length > 0) {
return x;
}
}
}
function getArray(json, keyName, isParent) {
let z = {};
if (!(getJSType(json) === "object") && !(getJSType(json) === "array")) {
z[keyName + 'Arr'] = '#' + getJSType(json);
} else {
z[keyName + 'Arr'] = convertJson(json, keyName, false);
}
outArr = Object.assign(outArr, z);
}
function getJSType(valToChk) {
function isUndefined(valToChk) {
return valToChk === undefined;
}
function isNull(valToChk) {
return valToChk === null;
}
function isArray(valToChk) {
return valToChk.constructor == Array;
}
function isBoolean(valToChk) {
return valToChk.constructor == Boolean;
}
function isFunction(valToChk) {
return valToChk.constructor == Function;
}
function isNumber(valToChk) {
return valToChk.constructor == Number;
}
function isString(valToChk) {
return valToChk.constructor == String;
}
function isObject(valToChk) {
return valToChk.constructor == Object;
}
if (isUndefined(valToChk)) {
return "undefined";
}
if (isNull(valToChk)) {
return "null";
}
if (isArray(valToChk)) {
return "array";
}
if (isBoolean(valToChk)) {
return "boolean";
}
if (isFunction(valToChk)) {
return "function";
}
if (isNumber(valToChk)) {
return "number";
}
if (isString(valToChk)) {
return "string";
}
if (isObject(valToChk)) {
return "object";
}
}
}
function formatJson() {
if (document.getElementById('code').value) {
try {
var inputTxt = JSON.parse(document.getElementById('code').value);
document.getElementById('code').value = JSON.stringify(inputTxt, null, 2);
document.getElementById('output').value = '';
} catch (e) {
document.getElementById('output').value = e;
}
}
}
function minifyJson() {
if (document.getElementById('code').value) {
try {
var inputTxt = JSON.parse(document.getElementById('code').value);
document.getElementById('code').value = JSON.stringify(inputTxt, null, null);
document.getElementById('output').value = '';
} catch (e) {
document.getElementById('output').value = e;
}
}
}
<html>
<head>
<title>JavaScript Code Runner</title>
</head>
<body>
<h3>Generate the Json Schema for Response</h3>
<div style="display: flex;">
<textarea id="code" style="flex: 1; height: 80vh;" spellcheck="false"></textarea>
<textarea id="output" style="flex: 1; height: 80vh; overflow: auto;" spellcheck="false"></textarea>
</div>
<div style="display: flex;height: 12;"></div>
<button onclick="runCode()">Generate Schema</button>
<button onclick="formatJson()">Format JSON</button>
<button onclick="minifyJson()">Minify JSON</button>
<script src="src/jsonconverter.js"></script>
<script>
function runCode() {
main();
}
</script>
</body>
</html>

Passing a parameter to a Component on instantiation

I'm creating TableViewColumns during runtime and need to pass the role to the TableViewColumn.
TableView {
model: myModel
onModelChanged: {
var roleList = myModel.customRoleNames
for ( var i = 0; i < roleList.length; ++i ) {
var role = roleList[ i ]
addColumn( /* my column component here */ )
}
}
}
Component {
id: columnComponent
TableViewColumn {
role: /* ??? */
}
}
How can I feed the role to my Component when it's being instantiated?
Ok, I've got it. Here is the solution:
TableView {
id: myTableView
model: myModel
onModelChanged: {
var roleList = myModel.customRoleNames
for ( var i = 0; i < roleList.length; ++i ) {
var role = roleList[ i ]
addColumn( columnComponent.createObject ( myTableView, { "role": role } ) )
}
}
}
Component {
id: columnComponent
TableViewColumn { }
}
This, of course, works for all properties of TableViewColumn, eg.:
addColumn( columnComponent.createObject ( myTableView, { "role": myRole, "title": someTitle } ) )

Codeception: acceptance test with selenium fails on "textarea"

I've got a function:
public function waitAndFill($element, $value, $timeOut = null)
{
$I = $this;
$I->_waitFor($element, $timeOut);
$I->fillField($element, $value);
$I->seeInField($element, $value);
}
And I use it like this:
$I->waitAndFill('#inputInfo', 'This is test info');
The textarea looks as follows
<textarea id="inputInfo"
name="company_description"
ng-model="company.company_description"
class="form-control"></textarea>
So, my test fails with this:
Step I see in field "#inputInfo","This is test info"
Fail Failed testing for 'This is test info' in company_description's value:
Failed asserting that an array contains 'This is test info'.
It works fine on <input> fields, but fails on <textarea>. Looks like it doesn't see any text at all.
This text is present on the screen shot made by the test.
What am I doing wrong?
It's a bug. The problem is this: $I->seeInField($element, $value); invokes $this->proceedSeeInField(array $elements, $value); which invokes a method getText() on the Facebook\WebDriver\Remote\RemoteWebElement object that it finds. If you read the documentation for Facebook\WebDriver\Remote\RemoteWebElement#getText() method it says that it returns the innerText for that element. So that's no bueno. To workaround this I removed the conditional for the textarea in this function.
protected function proceedSeeInField(array $elements, $value)
{
$strField = reset($elements)->getAttribute('name');
if (reset($elements)->getTagName() === 'select') {
$el = reset($elements);
$elements = $el->findElements(WebDriverBy::xpath('.//option[#selected]'));
if (empty($value) && empty($elements)) {
return ['True', true];
}
}
$currentValues = [];
if (is_bool($value)) {
$currentValues = [false];
}
foreach ($elements as $el) {
if ($el->getTagName() === 'textarea') {
$currentValues[] = $el->getText();
} elseif ($el->getTagName() === 'input' && $el->getAttribute('type') === 'radio' || $el->getAttribute('type') === 'checkbox') {
if ($el->getAttribute('checked')) {
if (is_bool($value)) {
$currentValues = [true];
break;
} else {
$currentValues[] = $el->getAttribute('value');
}
}
} else {
$currentValues[] = $el->getAttribute('value');
}
}
return [
'Contains',
$value,
$currentValues,
"Failed testing for '$value' in $strField's value: " . implode(', ', $currentValues)
];
}
You should change it to:
protected function proceedSeeInField(array $elements, $value)
{
$strField = reset($elements)->getAttribute('name');
if (reset($elements)->getTagName() === 'select') {
$el = reset($elements);
$elements = $el->findElements(WebDriverBy::xpath('.//option[#selected]'));
if (empty($value) && empty($elements)) {
return ['True', true];
}
}
$currentValues = [];
if (is_bool($value)) {
$currentValues = [false];
}
foreach ($elements as $el) {
if ($el->getTagName() === 'input' && $el->getAttribute('type') === 'radio' || $el->getAttribute('type') === 'checkbox') {
if ($el->getAttribute('checked')) {
if (is_bool($value)) {
$currentValues = [true];
break;
} else {
$currentValues[] = $el->getAttribute('value');
}
}
} else {
$currentValues[] = $el->getAttribute('value');
}
}
return [
'Contains',
$value,
$currentValues,
"Failed testing for '$value' in $strField's value: " . implode(', ', $currentValues)
];
}
Now it calls getAttribute('value') just like any other input element.
The is in file WebDriver.php