Category Archives: Magento

How To Login Magento Customer Account Programmatically

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){

    }

How To Get Regular Price Of Magento Bundle Product

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 To Login Magento Admin Panel Programmatically

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 To Duplicate Magento Product Programmatically

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();