I would like to know how to empty Magento cart programmatically
You should use “delete” method to empty Magento cart programmatically.
$quote = Mage::getSingleton('checkout/session')->getQuote(); $quote->delete();
I would like to know how to empty Magento cart programmatically
You should use “delete” method to empty Magento cart programmatically.
$quote = Mage::getSingleton('checkout/session')->getQuote(); $quote->delete();
How can I login Magento customer account programmatically
You will need to load the Magento customer object first and then call login method
$email = "test@test.com"; $password = "test"; $websiteId = Mage::app()->getWebsite()->getId(); $store = Mage::app()->getStore(); $customer = Mage::getModel("customer/customer"); $customer->website_id = $websiteId; $customer->setStore($store); try { $customer->loadByEmail($email); $session = Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer); $session->login($email, $password); }catch(Exception $e){ }
I would like to get the regular price of Magento bundle product without discount
You can use getSelectionsCollection to get all regular price of the options.
$pid = 1; $p = Mage::getModel('catalog/product')->load($pid); $_regularPrice = 0; $bcollection = $p->getTypeInstance(true)->getSelectionsCollection($p->getTypeInstance(true) ->getOptionsIds($p), $p); foreach ($bcollection as $bitem) { $_regularPrice += $bitem->getPrice() ; }
How can I logout the Magento admin user programmatically
You can delete the admin cookies to logout the Magento admin user
$adminSession = Mage::getSingleton('admin/session'); $adminSession->unsetAll(); $adminSession->getCookie()->delete($adminSession->getSessionName());
How can I mark Magento order as hold programmatically
You can use “setState” method to change the status of the order.
$order->setState(Mage_Sales_Model_Order::STATE_HOLDED, true)->save();
How can I login the admin panel by admin username programmatically
You may need “adminhtml/url”, “admin/user” and “admin/session” modules to login Magento admin panel with given Magento admin username.
$username = ”adminusername”; // here admin is username $user = Mage::getModel(”admin/user”)->loadByUsername($username); if (Mage::getSingleton(”adminhtml/url”)->useSecretKey()){ Mage::getSingleton(”adminhtml/url”)->renewSecretUrls(); } $session = Mage::getSingleton(”admin/session”); $session->setIsFirstVisit(true); $session->setUser($user); $session->setAcl(Mage::getResourceModel(”admin/acl”)->loadAcl()); Mage::dispatchEvent(”admin_session_user_login_success”,array(”user”=>$user)); if ($session->isLoggedIn()){ $redirectUrl = Mage::getSingleton(”adminhtml/url”)->getUrl(Mage::getModel(”admin/user”)->getStartupPageUrl(), array(”_current” => false)); header(”Location: ” . $redirectUrl); exit; }
How can I subscribe Magento Newsletter by email programmatically
You can call “subscribe” method to subscribe Magento Newsletter by given email
Mage::getModel('newsletter/subscriber')->subscribe('demo@demo.com');
How can I unsubscribe the Magento Newsletter Subscriber by email address programmatically
You can “unsubscribe” method to unsubscribe the Magento Newsletter Subscriber
Mage::getModel('newsletter/subscriber')->loadByEmail('demo@demo.com')->unsubscribe();
How can I delete a Magento order by order id programmatically
You can call “delete” method to remove the Magento order
$incrementId = 1; Mage::getModel('sales/order')->loadByIncrementId($incrementId)->delete();
How can I duplicate a Magento product by product id programmatically
You can call Magento’s product object’s method – “duplicate()” to duplicate the Magento product
$id = 1; $product = Mage::getModel('catalog/product')->load($id); $clone = $product->duplicate(); $clone = $clone->load( $clone->getId() ); $clone->setSku( 'newsku' ); $clone->save();