Add the products of a previously placed order to the basket (download link)

this is my first attempt to write a little module or extension.

i would like the user to have the possibility to add the products of a previously placed order from account order history to the basket. i have inserted an ‘add to cart’-button under each order. using the functionality of oxcmp_basket, this should not be too complicated.my question is, what is the smartest way of implenting it?is there any possibility of overwriting oxcmp_basket, or where should i place the code?thanks in advance.

Hi rdx,

actually this is pretty similar to the wishlist function, isn’t it?

By putting an article to the wishlist, it is saved to the oxorder (oxorderarticles?) table but gets a special flag in the database.

Yes, the oxcmp_basket shall be overridable. As you are asking where to put the code to: Do you know the articles about "How to write a module?"http://www.oxid-esales.com/en/category/24/192/228http://www.oxid-esales.com/de/news/blog/howto-extend-oxid-eshop-modules-part-1 (MaFi promised to come out with v2 pretty soon)http://www.oxid-esales.com/files/t3n_nr15_oxid_workshop.pdf (German only)http://www.oxid-esales.com/en/resources/forum/entwickler/rotation-aber-wie (German only)Would be glad to hear you were successfull! :slight_smile:


Marco Steinhäuser
Community Guide
OXID eSales AG

hi marco,thanks a lot for the tutorials.my first thought was to extend the template account-orders with hidden-fields containing article-id, amount, etc. and then calling an own method in a my_oxcmp_basket-class which extends oxcmp_basket. reading the articles from the db (orders) would also be an option.but first i will go through the tutorials. :slight_smile:

Of course. It’s open source and you might do everything you want in this manner actually, BUT:

Be aware of the next update. That’s why we propose writing modules for adopting functionalities.

Cheers


Marco Steinhäuser
Community Guide
OXID eSales AG

i thought maybe adding new ‘cmp_’-classes is part of the module-concept. but anyway, i will overwrite an existing class and create a module.

went through the tutorials - good basic information.

just another short question. :slight_smile:

is it possible to create a new ‘cmp_’-class instead of overwriting maybe oxcmp_basket?

regards.

TBO: I am not really sure… Give me some time to figure out how it works with that cmps.

Cheers


Marco Steinhäuser
Community Guide
OXID eSales AG

of course, there’s no hurry.

hi marco,

put together a very basic version that seems to work. :slight_smile:

created a module that extends oxcmp_basket.

Hi rdx,

it is possible to add own modiules to the eShop, but you’ll have to edit one single line in existing code:

  • write a cmp class (similar to the existing ones)

  • edit the oxUBase class and add your cmp to the array "$_aUserComponentNames "

  • be aware that an update might change oxUBase class in the future

But in your case extending the oxcmp_basket class seems to be the better way because what you do is basket functionality.

I hope I was able to help

Mathias

hi mathias,
thanks a lot. yes, i found this in the code, but i will not change anything in the core-classes (update). i extended oxcmp_basket. it only took a few lines of code and seems to work pretty well.

hi,
so this is my first module, i would like to post the code here. maybe some more experienced members have some improvements.
the purpose of this little module is to put a button ‘add to cart’ under each order in account-order-history. by clicking this button
the articles of the order are added to the basket.

regards.

added this to account_order.tpl:

[code type=“smarty”]
[{foreach from=$oView->getOrderList() item=order }]

[{ $oViewConf->getHiddenSid() }]
[{ $oViewConf->getNavFormParams() }]

[{/foreach }]




[code type="php"]

class ext_oxorder extends ext_oxorder_parent
{
	public function makeSelListArray( $sArtId = null, $sOrderArtSelList = null )
	{
		$this->_makeSelListArray( $sArtId, $sOrderArtSelList );
	}
}


[code type=“php”]
// oxcmp_basket => reorder/ext_oxcmp_basket
// oxorder => reorder/ext_oxorder

class ext_oxcmp_basket extends ext_oxcmp_basket_parent
{
const OverwriteArticleAmount = false;

public function reorder()
{
	if ( oxUtils::getInstance()->isSearchEngine() )
        		return;

	$myConfig = $this->getConfig();
	$sOrderNr = oxConfig::getParameter( 'oxordernr' );
	$oUser    = $this->getUser();

	if ( !$oUser )
		return;

	$oOrderList = $oUser->getOrders();
	$oCurOrder = null;
	
	foreach( $oOrderList as $oOrder )
		if ( $oOrder->oxorder__oxordernr->value == $sOrderNr ) {
			$oCurOrder = $oOrder;
			break;
		}

	if ( !$oCurOrder )
		return;

	$oOrderArticleList = $oOrder->getOrderArticles();

	$oArticleList = oxNew( 'oxarticlelist' );
	$oArticleList->loadOrderArticles( array( $oCurOrder->getId() =>
		$oCurOrder ) );

	$aArticles = array();

	foreach( $oOrderArticleList as $oOrderArticle ) {
		$oCurArticle = $oArticleList[ $oOrderArticle->oxorderarticles__oxartid->value ];

		if ( !$oCurArticle->isBuyable() )
			continue;

		$sArtId      = $oOrderArticle->oxorderarticles__oxartid->value;
		$dAmount     = $oOrderArticle->oxorderarticles__oxamount->value;
		$sSelVariant = $oOrderArticle->oxorderarticles__oxselvariant->value;

		$aSelVariant = $oOrder->makeSelListArray( $sArtId, $sSelVariant );
		$aPersParam = ( ( $oOrderArticle->oxorderarticles__oxpersparam->value ) ?
			unserialize( $oOrderArticle->oxorderarticles__oxpersparam->value ) :
			null );

		$aArticleInfo[ 'aid' ] = $sArtId;
		$aArticleInfo[ 'am' ] = $dAmount;
		$aArticleInfo[ 'sel' ] = $aSelVariant;
		$aArticleInfo[ 'persparam' ] = $aPersParam;
		$aArticleInfo[ 'override' ] = self::OverwriteArticleAmount;

		$aArticles[ $sArtId ] = $aArticleInfo;  
	}

	if ( count( $aArticles ) ) {
		$oBasketItem = $this->_addItems( $aArticles );

		if ( $oBasketItem && $myConfig->getConfigParam( 'iNewBasketItemMessage' ) != 0 ) {
			$oNewItem = new OxstdClass();
			$oNewItem->sTitle  = $oBasketItem->getTitle();
			$oNewItem->sId     = $oBasketItem->getProductId();
			$oNewItem->dAmount = $oBasketItem->getAmount();
			$oNewItem->dBundledAmount = $oBasketItem->getdBundledAmount();

			oxSession::setVar( '_newitem', $oNewItem );
		}

		$sReturn = $this->_getRedirectUrl();
	}
	else	
		$sReturn = '';

	return $sReturn;
}

}

just a few hints what you could change … you don’t need to if it works ( I haven’t tried it yet)

I would have done it in a different way getting the article ids in the same way as u but then using oxbasket->addToBasket function to add the articles again to basket.

Additionally you could add OverwriteArticleAmount to the config.inc.php or to the config table.

Basically thats a cool solution and I actually need the same functionality in a project, so will you make a full module out of this code and publish it open source? I could help u with this if you want.

If not, would u allow me to reuse some of your lines to make this as a module myself?

Greetings

Mathias

hi mathias,of course i will make a full module out of it. if you would like to help me - great.

just tell me which functionality you would add to it.my last decision was either using this approach or the oxbasket->addToBasket function. i will have a look at the code again - maybe i missed something.

regards,ralf

i used oxcmp_basket->_additems, because it uses oxbasket->addToBasket but also implements an exception-handling. i thought if itsnecessary to update this, oxid will take care of it :). but if you have a better solution - we’ll use that one.

oh even better … I haven’t seen that :slight_smile: very good! now I’m really looking forward to use your module :wink:

hi mathias,first version :slight_smile: of the module is ready - just some testing.

if you like, i could send it to you.regards.

hi,

here is a link to download the module: Reorder

regards,
ralf