Closed wajahatbashir closed 2 years ago
Hi,
It seems that your preorder attribute is of type Yes/No.
Have you tried to use it like a boolean?
if ($item->product->preorder && ...
You can also activate the debug option to understand how the configuration is evaluated.
A.L.
Hi,
Yes, preorder attribute is a type Yes/No, Please check this screenshot link.
Can you please correct this condition ?
if ($item->product->preorder == 0) OR if ($item->product->preorder == 'No')
I have tried both of this but not working.
and which condition i'll use for Product is In-stock or Out of stock ?
I have activate the debug option, that's coming empty.
Regards,
In debugging getting this error : Unknown variable $item Debug:
if ($item->product->preorder == 'No') {
addMethod('id_0026', ['title' => "In-Stock", 'price' => 130]);
} else {
addMethod('id_0026', ['title' => "Free Shipping", 'price' => 0]);
}
preorder
product
$item
Unknown variable $item
Hi Team,
I have write this code But this function is not working twice : $request->package_qty
Code screenshot link: https://imgur.com/rXUwEuw
This Code is working fine:
if ($quote->base_subtotal <= 364 ) {
addMethod('id_0025', [
'title' => "Flat Rate In-Stock",
'enabled' => count(
array_filter($request->all_items, function ($item) {
return $item->product->preorder == 0;
})
) == $request->package_qty,
'price' => 130,
]);
}
Now in below code $request->package_qty is not working, when i remove this line then code is working fine.
if ($quote->base_subtotal > 364 ) {
addMethod('id_0026', [
'title' => "Free In-Stock",
'enabled' => count(
array_filter($request->all_items, function ($item) {
return $item->product->preorder == 0;
})
) == $request->package_qty,
'price' => 0
]);
}
In debugging getting this error : Unknown variable $item Debug:
if ($item->product->preorder == 'No') { addMethod('id_0026', ['title' => "In-Stock", 'price' => 130]); } else { addMethod('id_0026', ['title' => "Free Shipping", 'price' => 0]); } preorder product $item Unknown variable $item
$item
variable cannot be used outside of a loop as it comes from $request->all_items
that is an collection of items
Now in below code $request->package_qty is not working, when i remove this line then code is working fine.
Why do you say it is not working? Which error do you have?
Now in below code $request->package_qty is not working, when i remove this line then code is working fine.
Why do you say it is not working? Which error do you have?
Debugging Code Screenshot: https://imgur.com/z6cCYQU
==> there is not showing any bug or error in debugger, But shipping method is not showing. But when i just remove this line of code $request->package_qty
Then shipping method is showing.
Actual code with issue:
if ($quote->base_subtotal > 364 ) {
addMethod('id_0026', [
'title' => "Free In-Stock",
'enabled' => count(
array_filter($request->all_items, function ($item) {
return $item->product->preorder == 0;
})
) == $request->package_qty, // Error in this line
'price' => 0
]);
}
The debug tells you why the enabled condition is evaluated to false.
Have you checked this.
You do not use $item->qty
in your condition.
Maybe that's the reason why the count does not match
$request->package_qty
.
A.L.
On Thu, Jul 21, 2022, 13:08 Wajahat Bashir @.***> wrote:
Now in below code $request->package_qty is not working, when i remove this line then code is working fine.
Why do you say it is not working? Which error do you have?
Debugging Code Screenshot: https://imgur.com/z6cCYQU
==> there is not showing any bug or error in debugger, But shipping method is not showing. But when i just remove this line of code $request->package_qty
Then shipping method is showing.
Actual code with issue:
if ($quote->base_subtotal > 364 ) { addMethod('id_0026', [ 'title' => "Free In-Stock", 'enabled' => count( array_filter($request->all_items, function ($item) { return $item->product->preorder == 0; }) ) == $request->package_qty, 'price' => 0 ]); }
— Reply to this email directly, view it on GitHub https://github.com/owebia/magento2-module-advanced-shipping/issues/109#issuecomment-1191352090, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAETURLRYV2YSMT3VDGXD3TVVEVRRANCNFSM54DHQYBA . You are receiving this because you commented.Message ID: @.*** com>
I could no find why count is showing false in this code.
2 things i have noticed
if ($quote->base_subtotal > 364 ) {
addMethod('id_0026', [
'title' => "Free In-Stock",
'enabled' => count(
array_filter($request->all_items, function ($item) {
return $item->product->preorder == 0;
})
) == $request->package_qty,
'price' => 0,
]);
}
Kindly help to fix this issue, what's going wrong with this code ?
Hi,
I suppose that you are using a single item in the cart with a quantity greater than 1 to test the condition > 364.
But your code does not take into account the quantity of items.
You should use something like this instead:
array_sum(
array_map(
function ($item) {
return $item->product->preorder == 0 ? $item->qty : 0;
},
$request->all_items
)
)
A.L.
Thanks a lot, this code is working perfectly. :)
Hi,
I want to show multiple shipping method but on base of product attribute condition. But this is not working for me.
Preorder is product attribute code. and it's dropdown.
I am trying to add this condition ( If Preorder is No and Product is Out of Stock then this custom shipping method should be display.) But this condition is not working. no shipping method is loading.
Can you please correct this condition ? I am using Magento 2.4.0.