Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Oct 22 2018 09:05
    @matks banned @Kamelia2000
Grzegorz Zawadzki
@seigieu
thank you for clearing my doubts ;)
Jean-Charles van der Bruggen
@Nakira

Hello All,
In a multiShop Context, I have one Product with a different price for each Shop.
I am trying to get the price for each shop in a cron task using SetContext, but I get the same price for each shop :

$shops = \Shop::getShops();
        foreach ($shops as $shop) {
            \Shop::setContext(\Shop::CONTEXT_SHOP, (int)$shop['id_shop']);
            var_dump($product->price); // -> Always get the same price, but im sure the product has different price on each shop
        }

What am I missing?

Grzegorz Zawadzki
@seigieu
You probably need to recreate object (load again new Product) each time you change context
Jean-Charles van der Bruggen
@Nakira
tried, same result
Grzegorz Zawadzki
@seigieu
1.6?
Jean-Charles van der Bruggen
@Nakira
1.7.6.1
Grzegorz Zawadzki
@seigieu
public function __construct($id = null, $id_lang = null, $id_shop = null) last parameter is $id_shop. Tried it?
Sorry.. thats forObject Model.
public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
That's for product
Jean-Charles van der Bruggen
@Nakira
trying
Grzegorz Zawadzki
@seigieu
it's from 1.6, but I don't think it has changed
```$shops = \Shop::getShops();
foreach ($shops as $shop) {
        var_dump((new Product($id_product, false, $id_lang, $shop['id_shop']))->price); // -> Always get the same price, but im sure the product has different price on each shop
    }```
Jean-Charles van der Bruggen
@Nakira
works, thanks. This is really disturbing.
$shops = \Shop::getShops();
        foreach ($shops as $shop) {
            \Shop::setContext(\Shop::CONTEXT_SHOP, (int)$shop['id_shop']);
            $product=new \Product($product->id,false,null,(int)$shop['id_shop']);
            var_dump($product->price);
        }
Grzegorz Zawadzki
@seigieu
What a mess... :D
what is disturbing?
Jean-Charles van der Bruggen
@Nakira
what i don't understand is that when inserting a product in multistore i use the context and it works fine. BUT for loading product I need to use the construct
But ok, i get the idea :-D
thank you @seigieu
Grzegorz Zawadzki
@seigieu
it's confusing.. true
wonder how front loads prices tbh, never checked ;D
Pablo Borowicz
@eternoendless
@Nakira you need to update your shop in Context
Context::getContext()->shop
Muhamad Reza Saddat
@rezasaddat
hello everyone can i ask, i have problem with connect to presta webservice using curl http in my server
but using postman its possible , my server mod_rewrite is enable
but still not work, i got bad http response
can help this
Chris Rees
@zesda

@eternoendless

cart id may be zero actually https://github.com/PrestaShop/PrestaShop/blob/1.7.7.x/src/Core/Domain/Cart/ValueObject/CartId.php

The logic given on that page does not permit cart id to be zero

Pablo Borowicz
@eternoendless
you’re right @zesda, I got mixed up by the yoda condition
ping @seigieu
sorry
Grzegorz Zawadzki
@seigieu
yoda is the best ^^ strange to read tho :)
Chris Rees
@zesda
Yeah it's not my style either, good you saw this too @seigieu :)
Grzegorz Zawadzki
@seigieu
Ok... i got mixed up
0 >= $cartId
It got so complicated there with it :D
Chris Rees
@zesda
When in doubt look at the thrown CartConstraintException :)
Grzegorz Zawadzki
@seigieu
@eternoendless @zesda Acually i Belived Pablo and didnt check, from first look it looked like it allowed, but its working backward. Haha. So it may not be 0... that's strange.
But that complicates things a bit for me. As I'm creating orders imported from external system... and it may be, that product is not in shop anymore. So cannot find its ID anymore by reference.
Chris Rees
@zesda
Best to create a new disabled Product? Hopefully the dependencies should stop there...?
Grzegorz Zawadzki
@seigieu
I may as well and up creating empty cart.
Chris Rees
@zesda
Based on the previous Symfony error screenshot that might not work if it's trying to source the Cart Rules
Worth checking too
Grzegorz Zawadzki
@seigieu
Tt's a free module. 1.7 really wants me to drop support for it :laughing:
Chris Rees
@zesda
Looks like it! :D
Grzegorz Zawadzki
@seigieu
Anyway... its mailchimp who got problem. Orders are importing normally... so who cares.
Or can create and override to remove this restriction (Irony here - that's the reason i hate overrides... )
Chris Rees
@zesda
I've not worked with module overrides for 1.7, might be worth seeing if you can override the Formatters to prevent that behaviour
Bingo :)
Grzegorz Zawadzki
@seigieu
But changing this validation is also wrong... other modules may expect, that PS validates it is no 0... as mailchimp :D Programming has so many ethical problems :D
Still.. no1 cares about them... should I? :banana: