Why is mentric totatAdRevenue not working? - google-analytics

When using metric totalAdRevenue (admanager 360 link in GA4) the metric 'totalAdRevenue' is not giving any results. In GA4 Query explorer i do get the right data.
My Code:
$ar = [
'property' => 'properties/' . $PROP_ID,
'dateRanges' => [
new DateRange([
'start_date' => $date->format("Y-m-d"),
'end_date' => $date->format("Y-m-d"),
]),
],
'dimensions' => [new Dimension(
[
'name' => 'sessionCampaignName'
]
),
],
'metrics' => [new Metric(
[
'name' => 'sessions'
]
), new Metric(
[
'name' => 'totalAdRevenue'
]
)
]
];
$response = $analytics->runReport($ar);

Related

Get a order data from Awebsite and create order on website B Woocoomerce API

I want to get product_id (from Website A ) Woocommerce APi and create a order in website B
If from Website A product_id =11 then create product_id= 1050 in website B
If product_id =121 then create product_id= 160 in website B
function create_order_from( $customer_id, $new_customer_data, $password_generated ) {
$live_ck = 'ck_blablabla';
$live_cs = 'cs_blablabla';
$live_url = 'https://www.website.com/wp-json/wc/v3/orders?consumer_key=' . $live_ck . '&consumer_secret=' . $live_cs;
$customer = new WC_Customer( $customer_id );
$body = array(
'status' => 'completed',
'meta_data' => array( array(
'key' => 'createdby',
'value' => 'website'
)),
'total' => 0,
'billing' => array(
'first_name' => $customer->get_billing_first_name(),
'email' => $customer->get_email(),
),
'line_items' => array( array(
'product_id' => 1050,
'quantity' => 1,
)),
);
$raw_response = wp_remote_post( $live_url,
array(
'headers' => array( 'Content-Type' => 'application/json' ),
'timeout' => 30,
'body' => json_encode( $body ),
)
);
}```
THank you for your help

How to add product attributes programmatically?

if i try this:
$arr = [
'pa_yacht-dozvillya' => [
'name' => 'pa_yaht-dozvillya',
'value' => 'Акваскутер',
'is_visible' => 1,
'is_taxonomy' => 1,
],
];
update_post_meta(2194, '_product_attributes', $arr);
then this adds an attribute with no value
here

How to get only nested data in Laravel collection

I wrote a database selection like this (Laravel 8):
$users = collect(User::with(['roles','roles.permissions'])->find(21));
The result is the following
=> Illuminate\Support\Collection {#2051
all: [
"id" => 21,
"first_name" => "test",
"name" => "test",
"..." => "...",
"roles" => [
[
"id" => 9,
"name" => "Test",
"permissions" => [
[
"id" => 13,
"name" => "userReadList",
],
[
"id" => 11,
"name" => "userUpdate",
],
],
],
[
"id" => 4,
"name" => "responsible",
"permissions" => [
[
"id" => 10,
"name" => "userRead",
],
[
"id" => 9,
"name" => "userCreate",
],
],
],
],
],
}
Now: What I have to change in the query to get only an array, containing the permissions id as follow: [13,11,10,9]?
Or is my query principal wrong for getting the permissions id
I found the solution:
$userPermissions = collect(User::with(['roles','roles.permissions'])->find(21));
Arr::flatten(Arr::pluck($userPermissions['roles'] , 'permissions.*.id'));
//[13,11,1,4,]
But I think, the better way is the following
$userPermissions = User::with(['roles','roles.permissions'])->find(21);
$userPermissions->roles->pluck('permissions.*.id')->flatten()->toArray();
//[13,11,1,4,]
Also possible it the following approach
$userPermissions = User::with(['roles','roles.permissions'])->where('id',21)->get();
$userPermissions->pluck('roles.*.permissions.*.id')->flatten()->toArray();
//[13,11,1,4,]

How do we get this array output?

We need this output:
$filters = [
['property' => 'status.id', 'expression' => '!=', 'value' => 5],
['property' => 'status.id', 'expression' => '!=', 'value' => 1],
['property' => 'status.id', 'expression' => '!=', 'value' => 7],
];
and this way doesn't work:
foreach ($orderStatusItems as $orderStatusItem) {
$filters[] .= "['property' => 'status.id', 'expression' => '!=', 'value' => $orderStatusItem],";
}
here is the solution:
$orderFilters = [];
foreach ($orderStatusItems as $orderStatusItem) {
array_push($orderFilters, ['property' => 'status.id', 'expression' => '!=', 'value' => $orderStatusItem]);
}

Symfony 3.4 file is not validated when using createFormBuilder

Here is what I have tried:
$form = $this->createFormBuilder(null, ['method' => 'POST', 'csrf_protection' => false])
->add('file', FileType::class, [
'required' => true,
'constraints' => [
new File([
'mimeTypes' => [
'application/pdf',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'image/gif',
'image/png',
'image/jpeg',
'application/vnd.oasis.opendocument.text',
'application/vnd.oasis.opendocument.spreadsheet'
]
]),
new Count(['min' => 1, 'max' => 1])
]
])
//->add('submit', SubmitType::class)
->getForm();
$form->handleRequest($request);
// $form->submit($request->request->all(), false);
$form->submit($request->files->get($form->getName()));
// $this->
// if ($form->isValid()) {
if (/*$form->isSubmitted() &&*/ $form->isValid()) {
Handle request does not submit form. If I call submit after handle request, it still does not validate.
I even tried
/** #var UploadedFile $f */
$f = $request->files->get('file');
$violations = $this->container->get('validator')->validate($f, [
new File([
'mimeTypes' => [
'application/pdf',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'image/gif',
'image/png',
'image/jpeg',
'application/vnd.oasis.opendocument.text',
'application/vnd.oasis.opendocument.spreadsheet'
]
]),
new Count(['min' => 1, 'max' => 1])
]);
But validate gives error:
Expected argument of type "array or \Countable", "Symfony\Component\HttpFoundation\File\UploadedFile" given.
0 /home/darius/PhpstormProjects/surplus/vendor/symfony/symfony/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php(829):
Symfony\Component\Validator\Constraints\CountValidator->validate(Object(Symfony\Component\HttpFoundation\File\UploadedFile), Object(Symfony\Component\Validator\Constraints\Count))
1 /home/darius/PhpstormProjects/surplus/vendor/symfony/symfony/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php(675):
Symfony\Component\Validator\Validator\RecursiveContextualValidator->validateInGroup(Object(Symfony\Component\HttpFoundation\File\UploadedFile),
'000000006bcba97...',
Object(Symfony\Component\Validator\Mapping\GenericMetadata),
'Default',
Object(Symfony\Component\Validator\Context\ExecutionContext))
2 /home/darius/PhpstormProjects/surplus/vendor/symfony/symfony/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php(118):
Symfony\Component\Validator\Validator\RecursiveContextualValidator->validateGenericNode(Object(Symfony\Component\HttpFoundation\File\UploadedFile),
NULL, '000000006bcba97...',
Object(Symfony\Component\Validator\Mapping\GenericMetadata), '',
Array, NULL, 1,
Object(Symfony\Component\Validator\Context\ExecutionContext))
3 /home/darius/PhpstormProjects/surplus/vendor/symfony/symfony/src/Symfony/Component/Validator/Validator/RecursiveValidator.php(100):
Symfony\Component\Validator\Validator\RecursiveContextualValidator->validate(Object(Symfony\Component\HttpFoundation\File\UploadedFile), Array, Array)
4 /home/darius/PhpstormProjects/surplus/vendor/symfony/symfony/src/Symfony/Component/Validator/Validator/TraceableValidator.php(65):
Symfony\Component\Validator\Validator\RecursiveValidator->validate(Object(Symfony\Component\HttpFoundation\File\UploadedFile), Array, NULL)
5 /home/darius/PhpstormProjects/surplus/src/STL/TaxCalculatorBundle/Controller/Api/TaxCalculatorController.php(357):
Symfony\Component\Validator\Validator\TraceableValidator->validate(Object(Symfony\Component\HttpFoundation\File\UploadedFile), Array)
6 /home/darius/PhpstormProjects/surplus/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php(151):
STL\TaxCalculatorBundle\Controller\Api\TaxCalculatorController->uploadAction(300,
Object(Symfony\Component\HttpFoundation\Request),
Object(FOS\RestBundle\Request\ParamFetcher))
7 /home/darius/PhpstormProjects/surplus/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php(68):
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request),
1)
8 /home/darius/PhpstormProjects/surplus/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(202):
Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request),
1, true)
9 /home/darius/PhpstormProjects/surplus/web/app_dev.php(32): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request))
10 {main}
I see this is not as in documentation example, but I want to not refactor much if possible. This should be simple fix but I spent few hours and cannot find.
$violations = $this->container->get('validator')->validate($f, [
new File([
'mimeTypes' => [
'application/pdf',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'image/gif',
'image/png',
'image/jpeg',
'application/vnd.oasis.opendocument.text',
'application/vnd.oasis.opendocument.spreadsheet'
]
]),
//new Count(['min' => 1, 'max' => 1])
]);
The problem was new Count. It is not needed because for validate method if we upload multiple files, then $f will be array and there will be exception, so user will not be able to upload multiple files.

Resources