Order again from history

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Order again from history

Post by MikaelNazarenko » 21 Jun 2022, 05:22

Hi Aimeos community !

You know, in personal account we have orders history.

Do you have some solutions or ideas how to integrate function to put all products from specific order to basket just with click and buy them again ?

Thanks !

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: Order again from history

Post by MikaelNazarenko » 21 Jun 2022, 06:30

This is code I use:

Code: Select all

        if(\Request::get('his_action') == 'buy-again' && ($his_id = \Request::get('his_id'))) {

            $domains = ['attribute', 'media', 'price', 'product', 'text'];

            /** @var \Aimeos\Controller\Frontend\Basket\Decorator\CustomSelect $basketCntl */
            $basketCntl = \Aimeos\Controller\Frontend::create( $context, 'basket' );
            $productCntl = \Aimeos\Controller\Frontend::create( $context, 'product' )->uses( $domains );

            /** @var \Aimeos\MShop\Common\Manager\Decorator\Depth $orderManager */
            $orderManager = \Aimeos\MShop::create( $context, 'order' );
            /** @var \Aimeos\MShop\Order\Item\Standard $orderItem */
            $orderItem = $orderManager->get( $his_id, ['order/base', 'order/base/address', 'order/base/product', 'order/base/service', 'order/base/product/attr'] );

            /** @var \Aimeos\MShop\Order\Item\Base\Standard $basket */
            $basket = $basketCntl->load( $orderItem->getBaseId() );

            /** @var \Aimeos\MShop\Order\Item\Base\Product\Standard $product */
            foreach ($basket->getProducts() as $product) {
                $attributes = [
                    'variant' => [],
                    'custom' => [],
                    'config' => []
                ];

                /** @var \Aimeos\MShop\Order\Item\Base\Product\Attribute\Standard $attributeItem */
                foreach ($product->getAttributeItems() as $attributeItem) {
                    if($attributeItem->getType() == 'variant') {
                        $attributes[$attributeItem->getType()][$attributeItem->getCode()] = $attributeItem->getAttributeId();
                    } elseif($attributeItem->getType() == 'custom') {
                        $attributes[$attributeItem->getType()][$attributeItem->getAttributeId()] = $attributeItem->getValue();
                    } elseif($attributeItem->getType() == 'config') {
                        $attributes[$attributeItem->getType()]['qty'][] = $attributeItem->getQuantity();
                        $attributes[$attributeItem->getType()]['id'][] = $attributeItem->getAttributeId();
                    }
                }

                $basketCntl->addProduct( $productCntl->get( $product->getProductId() ),
                    $product->getQuantity(),
                    $attributes['variant'],
                    $this->getAttributeMap( $attributes['config'] ),
                    $attributes['custom'],
                    $product->getStockType(),
                    $product->getSupplierId(),
                    $product->getSiteId()
                );
            }
        }
Maybe will be useful for someone. Any suggestions and improvements are welcome !

User avatar
aimeos
Administrator
Posts: 7873
Joined: 01 Jan 1970, 00:00

Re: Order again from history

Post by aimeos » 21 Jun 2022, 06:40

The feature is already available since 2-3 years:
https://github.com/aimeos/ai-client-htm ... #L329-L368
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: Order again from history

Post by MikaelNazarenko » 21 Jun 2022, 09:20

Wow ! Great !

And is it available in the following version ?

Code: Select all

aimeos/ai-client-html              2021.10.5 Aimeos ai-client-html extension

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: Order again from history

Post by MikaelNazarenko » 21 Jun 2022, 09:48

Sorry, my mistake. The function is there. Great !) You can remove this topic )

Post Reply