Order again from history
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!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Order again from history
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 !
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 !
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: Order again from history
This is code I use:
Maybe will be useful for someone. Any suggestions and improvements are welcome !
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()
);
}
}
Re: Order again from history
The feature is already available since 2-3 years:
https://github.com/aimeos/ai-client-htm ... #L329-L368
https://github.com/aimeos/ai-client-htm ... #L329-L368
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: Order again from history
Wow ! Great !
And is it available in the following version ?
And is it available in the following version ?
Code: Select all
aimeos/ai-client-html 2021.10.5 Aimeos ai-client-html extension
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: Order again from history
Sorry, my mistake. The function is there. Great !) You can remove this topic )