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

[RESOLU] MAJ attribut eav par programmation
 
Pierre SII
Jr. Member
 
Total Posts:  25
Joined:  2008-12-19
Nice, France
 

Bonjour,

Je sollicite l’aide de la communauté pour un probleme qui me bloque depuis plus d’un jour. En voila un petit resumé:

0) J’utilise la conf suivante Magento Version 1.2.0.2.

1) J’ai “overloadé” le controller AccountController afin de personnaliser l’authentification des clients. Ca fonctionne nikel !

2) J’ai ensuite ajouté deux attributs eav (jcoId, (int), jcoUsername) au Model Customer ça fonctionne a 80 % (envirion hein grin ).

2.1) Ce qui est OK:
* la création des attribut dans les table eav
* la consultation et maj de ces deux attributs via l’interface admin des client (admin>Clients>Gérer les clients). Dans l’écran “Informations du compte” je vois bien les deux attributs et je peux mettre a jour les valeurs. Jusque la tout bien.

2.2) Ce qui est KO:
* dans le code PHP (AccountController::loginPostAction()) j’ai essaye de mettre a jour la valeur de ces attributs sans succès:

// Connect to JCO Webservices to get logged in
                    $jcoCustomer = new Jco_Soap_Client_JCOCustomer();
                    
$jcoCustomer->login($login['username']$login['password']);
                    
                    
// If we reach that point it means that the user has successfully logged in
                    
                    // We check if this JCO customer exist into Magento
                    
$customer Mage::getModel('customer/customer')
                        ->
setWebsiteId(Mage::app()->getStore()->getWebsiteId());
                    
                    
// We load the magento Customer
                    
$customer->loadByEmail($jcoCustomer->getEmail());
                    
                    
$customer->setJcoId($jcoCustomer->getId());
                    
$customer->setJcoUsername($jcoCustomer->getUsername());
                    
$customer->setFirstname("Pierre3");
                    
$customer->save();

* Après exécution du code ci-dessus le prénom est bien mis a jour
* Par contre les deux attributs eav ne le sont pas :(
* Aucune exception n’est levé.

3) Voila ma conf :

le fichier app/code/local/Jco/Customer/etc/config.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
Jco_Customer>
            <
version>0.1.0</version>
        </
Jco_Customer>
    </
modules>
    <global>
        <
fieldsets>
            <
customer_account>
                <
jcoId><create>1</create><update>1</update></jcoId>
                <
jcoUsername><create>1</create><update>1</update></jcoUsername>
            </
customer_account>
        </
fieldsets>
        
        <
models>
            <
customer_entity>
                           <
rewrite>
                              <
setup>Jco_Customer_Model_Entity_Setup</setup>
                           </
rewrite>
                       </
customer_entity>
              </
models>
        
          <
resources>
                 <
customer_setup>
                    <
rewrite>
                        <
setup>Jco_Customer_Model_Entity_Setup</setup>
                    </
rewrite>
                 </
customer_setup>
             </
resources>
        
        <!-- 
This rewrite rule could be added to the database instead -->
        <
rewrite>
            <!-- 
This is an identifier for your rewrite that should be unique -->
            <!-- 
THIS IS THE CLASSNAME IN YOUR OWN CONTROLLER -->
            <
jco_customer_customer_account_loginPost>
                <
from><![CDATA[#^/customer/account/loginPost/?$#]]></from>
                
<!--
                    - 
customer matches the router frontname below
                    
account matches the path to your controller
                    
                    Considering the router below
"/customer/account/" will be
                    
"translated" to "/Jco/Customer/controllers/AccountController.php" (?)
                -->
                <
to>/customer/account/loginPost</to>
            </
jco_customer_customer_account_loginPost>
        </
rewrite>
    </global>
    <
frontend>
        <
routers>
            <
jco_customer>
                <!-- 
should be set to "admin" when overloading admin stuff (?) -->
                <use>
standard</use>
                <
args>
                    <
module>Jco_Customer</module>
                    <!-- 
This is used when "catching" the rewrite above -->
                    <
frontName>customer</frontName>
                </
args>
            </
jco_customer>
        </
routers>
    </
frontend>
</
config>

Suite voir post suivant…

 
Magento Community Magento Community
Magento Community
Magento Community
 
Pierre SII
Jr. Member
 
Total Posts:  25
Joined:  2008-12-19
Nice, France
 

.... Suite

le fichier /app/code/local/Jco/Customer/Model/Entity/Setup.php:

class Jco_Customer_Model_Entity_Setup extends Mage_Customer_Model_Entity_Setup
{
    
public function getDefaultEntities()
    
{
        
return array(
            
'customer' => array(
                
'entity_model'          =>'customer/customer',
                
'table'                 => 'customer/entity',
                
'increment_model'       => 'eav/entity_increment_numeric',
                
'increment_per_store'   => false,
                
'attributes' => array(
                    
'website_id' => array(
                        
'type'          => 'static',
                        
'label'         => 'Associate to Website',
                        
'input'         => 'select',
                        
'source'        => 'customer/customer_attribute_source_website',
                        
'backend'       => 'customer/customer_attribute_backend_website',
                        
'sort_order'    => 10,
                    ),
                    
'store_id' => array(
                        
'type'          => 'static',
                        
'label'         => 'Create In',
                        
'input'         => 'select',
                        
'source'        => 'customer/customer_attribute_source_store',
                        
'backend'       => 'customer/customer_attribute_backend_store',
                        
'visible'       => false,
                        
'sort_order'    => 20,
                    ),
                    ..........
                    
'jcoId' => array(
                        
'type'          => 'int',
                        
'label'         => 'JCO User Id',
                        
'sort_order'    => 61,
                    ),
                    
'jcoUsername' => array(
                        
'type'          => 'varchar',
                        
'label'         => 'JCO Username',
                        
'sort_order'    => 62,
                    ),
                    ..........
                ),
            ),

            
'customer_address'=>array(
                
'entity_model'  =>'customer/customer_address',
                
'table' => 'customer/address_entity',
                
'attributes' => array(
                    .......
                ),
            ),
        );
    
}
}

Bien sur le fichier /app/etc/modules/Jco_All.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
Jco_Customer>
            <
active>true</active>
            <
codePool>local</codePool>
        </
Jco_Customer>
    </
modules>
</
config>

S’il vous manque des infos n’hésitez pas a me les demander.

Merci d’avance pour votre aide.

Pierre

 
Magento Community Magento Community
Magento Community
Magento Community
 
Pierre SII
Jr. Member
 
Total Posts:  25
Joined:  2008-12-19
Nice, France
 

Re,

J’ai poster la traduction exact ce post dans le forum general > Programming questions.

http://www.magentocommerce.com/boards/viewthread/30625/

Oui oui fait l’effort d’y aller y a la reponse a mon probleme !

Cordialemenet,

Pierre

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