Page 1 of 1
Order again from history
Posted: 21 Jun 2022, 05:22
by MikaelNazarenko
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 !
Re: Order again from history
Posted: 21 Jun 2022, 06:30
by MikaelNazarenko
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 !
Re: Order again from history
Posted: 21 Jun 2022, 06:40
by aimeos
Re: Order again from history
Posted: 21 Jun 2022, 09:20
by MikaelNazarenko
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
Re: Order again from history
Posted: 21 Jun 2022, 09:48
by MikaelNazarenko
Sorry, my mistake. The function is there. Great !) You can remove this topic )