0

I am trying to update seller's group id in my multi-seller Magento website.

function becomesellerAction() {
$adminApproval = Mage::getStoreConfig('marketplace/admin_approval_seller_registration/need_approval');
$approval = 0;
if ($adminApproval == 1) {
    $approval = 0;
} else {
    $approval = 1;
}
$getGroupId = Mage::helper('marketplace')->getGroupId();
Mage::log($getGroupId,null,'logthis.log');
$customer = Mage::getSingleton("customer/session")->getCustomer();
$customer->setGroupId($getGroupId)->save();

In the log, I do see $getGroupId=4 which is what I want. But the database continues to have the default value of 1. Basically this is not saving the value to the database. The table in the database where this needs to be saved is 'customer_entity'.

I tried using a direct query:

$resource = Mage::getSingleton('core/resource');
$writeConnection = $resource->getConnection('core_write');
$getGroupId = Mage::helper('marketplace')->getGroupId();
$email = $customer->getEmail();
$query = "UPDATE customer_entity SET group_id = '{$getGroupId}' WHERE email = '{$email}'";
Mage::log($query, null,'query.log');

$writeConnection->query($query);

And this works fine in all environments.

Strangely the original code works fine in my local but not in test or production (local is WAMP and prod/test is Apache/Linux).

Any pointers to what am I doing wrong here? Is there a log that gets created when such save() operations fail?

0

it may be an Observer that stops it from saving. Impossible to specify it exactly.

You could start here and see what happens when you call save: https://github.com/bragento/magento-core/blob/1264aee821b451b3c88e55659cd1ee79d3b324af/app/code/core/Mage/Core/Model/Abstract.php#L317

  • I put the try / catch but it gives no error. In fact it gives a success message. I guess I will have to live with the direct query for now ... but its very perplexing – coderatlarge Feb 14 '16 at 2:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.