paolo@bimodesign.com | +34 608 61 64 10

E-Commerce

        

Magento, Daily Deal how to resolve but to assign merchant role

The magento Daily Deal module doesn't run correctly in order to assign a merchant role to the user.
As twice chances don't run I decided to modify one of them, where we first create a user and we assign them the merchant role. In this case, the Daily Deals module duplicates the userId and it doesn't assign the correct deal to the merchant.
I modify the file app/code/local/AdolMedia/DailyDeals/Model/Mysql4/Merchant.php and the else of the condition if($customer->getId()), adding this code (I'm using the direct SQL, cause I can't get the EntityId in Magento standard mode)

$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
     
$query = "SELECT entity_id 
            FROM customer_entity  
           WHERE email = '". $object->getMerchantEmail() . "' LIMIT 1";

$entityId = $readConnection->fetchOne($query);
$object->setCustomerId($entityId); 

This is the entire code of the _beforeSave method (I leave the comment code for the previous code

public function _beforeSave(Mage_Core_Model_Abstract $object){
	if(!$object->getMechantId() || $object->getCustomerId() == null){
            $customer = Mage::getModel('customer/customer');
            $customer->setWebsiteId(Mage::app()->getStore()->getWebsiteId());            
            $customer->loadByEmail($object->getMerchantEmail());
            
            if($customer->getId()){
                $customer_id = $customer->getId();
                $object->setCustomerId($customer_id);
                $customer->setIsMerchant(true);
                $customer->save();
            }else{
		//$randomPassword = $customer->generatePassword(8);
                //$customer->setId(null)
                //         ->setSkipConfirmationIfEmail($object->getMerchantEmail())
                //         ->setFirstname($object->getMerchantName())
                //         ->setEmail($object->getMerchantEmail().time())
                //         ->setPassword($randomPassword)
                //         ->setIsMerchant(true)
                //         ->setConfirmation($randomPassword);
                //$customer->save();    
                //$customer_id = $customer->getId();

                // PB - Modificacion para que no duplique el usuario y 
                //      asigne el codigo correcto del merchant
                // 
                $resource = Mage::getSingleton('core/resource');
                $readConnection = $resource->getConnection('core_read');
     
                $query = "SELECT entity_id FROM customer_entity  WHERE email = '". $object->getMerchantEmail() . "' LIMIT 1";
                $entityId = $readConnection->fetchOne($query);

                $object->setCustomerId($entityId);                
            }
        }
        parent::_beforeSave($object);
    }