Jump to content

Adding order programmatically Prestashop 1.7.7.0


Recommended Posts

Hi developers!

I was able to create orders programmatically on a custom module until 1.7.7.0 update. Now this exception is thrown:
Shop context types other than "single shop" are not supported

I tried adding this code lines without success

$shop = new Shop(1); $employee = new Employee(1); 

$this->context->employee = $employee; 

$this->context->shop = $shop; 

Shop::setContext(Shop::CONTEXT_SHOP, $shop->id);

Additional information

PrestaShop version: 1.7.7.0

PHP version: 7.2.25

Any help would be very appreciated! 

Edited by satislent (see edit history)

Share this post


Link to post
Share on other sites
  • 4 weeks later...

Hi, I managed to fix it for some orders, however the error still prompts in some cases. I'll have to investigate more.

        $this->context->cart = $cart;
        $currency = new Currency($id_currency);
        $this->context->currency = $currency;
        
        $shop = new Shop($id_shop);
        $employee = new Employee(1); 
        
        
        $this->context->employee = $employee;
        $this->context->shop = $shop;
        Shop::setContext(Shop::CONTEXT_SHOP, $shop->id);

 

Share this post


Link to post
Share on other sites

Thanks

I'm getting this with my payment method. It was fine with 1.7.6 but stopepd with 1.7.7

Uncaught PrestaShopBundle\\Exception\\NotImplementedException: Shop context types other than "single shop" are not supported in /src/PrestaShopBundle/Entity/Repository/StockManagementRepository.php:142

Part of the validation code:

if (isset($cart_id) && $cart_id != null)
{
        $context->employee = new Employee($idEmployee);
        $cart = new Cart($cart_id);
        $context->cart = $cart;
        if (!Validate::isLoadedObject($cart))
            exit;

 

Share this post


Link to post
Share on other sites
  • 2 weeks later...

Hello!

No I didn't. I tried to select the shop programmatically but the error persists.

So I deleted the error and now it works:

@

  src\PrestaShopBundle\Entity\Repository\CategoryRepository.php (1 hits)

  src\PrestaShopBundle\Entity\Repository\FeatureAttributeRepository.php (1 hits)

  src\PrestaShopBundle\Entity\Repository\StockManagementRepository.php (1 hits)
 

I changed:

if ($shop->getContextType() !== $shop::CONTEXT_SHOP) {
	//throw new NotImplementedException('Shop context types other than "single shop" are not supported');
	$this->shopId = 1;
}else{
	$this->shopId = $shop->getContextualShopId();
}

Also @ /classes/shop/Shop.php

public function getContextualShopId()
    {
        if ($this->getContextType() !== self::CONTEXT_SHOP) {
            //throw new LogicException('The retrieval of the contextual shop id is only possible in "single shop mode".');
            return 1;
        }

        return (int) self::$context_id_shop;
    }

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More