Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Get latest Product ID
 
NetzAgenten1
Jr. Member
 
Total Posts:  13
Joined:  2012-07-30
 

Hey there,

I need to get the latest inserted PRODUCT ID out of my Database...how do i do?

This is how i get the Product ID in AddtoCart

$productId = (int) $this->getRequest()->getParam('product');

but i need the latest inserted ID.

I´m on a script that duplicates the Product when I add it to cart ....to show this Product in Cart i need the latest Product ID.
Why? I got some calculations running on the fly and when a customer adds a product twice to cart both products get overwritten ....

 
Magento Community Magento Community
Magento Community
Magento Community
 
NetzAgenten1
Jr. Member
 
Total Posts:  13
Joined:  2012-07-30
 

Well thats not that what I´m looking for but I´m on my way....

I´m able to clone the Product in cartcontroller.php

/**
             * Check product availability
             */
            if (!$product{
                $this
->_goBack();
                return;
            
}

            $cart
->addProduct($product$params);
            if (!empty(
$related)) {
                $cart
->addProductsByIds(explode(\',\'$related));
            
}
            $cart
->save();
            
            
$clone=$product->duplicate();
            
$clone->setSku($clonedSku);
            
$clone->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);    
            
$clone->setPrice(); // 5€ = 5
            
$clone->setStatus(1); // AKTIV=1
            
$clone->setVisibility(4);
            
$clone->setTaxClassId(2);
            
$clone->setCategoryIds(\"93\");
            
$clone->getResource()->save($clone);

but now i got some problems with showing the cloned one in cart ....

And.. THANK YOU! =)

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top