Nie wiem, co próbowaliście, więc wymienię wszystkie kroki potrzebne do dodania nowego atrybutu klienta schooL do formularza rejestracji Magento 1.6.1.
Utwórz moduł najlepiej lub umieść kod podobny do tego w pliku .phtml i uruchom go raz. Jeśli robisz to właściwe i tworzenia modułu, umieścić kod jak to w pliku mysql_install:
<?php
$installer = $this;
$installer->startSetup();
$setup = Mage::getModel('customer/entity_setup', 'core_setup');
$setup->addAttribute('customer', 'school', array(
'type' => 'int',
'input' => 'select',
'label' => 'School',
'global' => 1,
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'default' => '0',
'visible_on_front' => 1,
'source'=> 'profile/entity_school',
));
if (version_compare(Mage::getVersion(), '1.6.0', '<='))
{
$customer = Mage::getModel('customer/customer');
$attrSetId = $customer->getResource()->getEntityType()->getDefaultAttributeSetId();
$setup->addAttributeToSet('customer', $attrSetId, 'General', 'school');
}
if (version_compare(Mage::getVersion(), '1.4.2', '>='))
{
Mage::getSingleton('eav/config')
->getAttribute('customer', 'school')
->setData('used_in_forms', array('adminhtml_customer','customer_account_create','customer_account_edit','checkout_register'))
->save();
}
$installer->endSetup();
?>
W pliku config.xml modułu. Zauważ, że nazwa mojego modułu to Excellence_Profile.
<profile_setup> <!-- Replace with your module name -->
<setup>
<module>Excellence_Profile</module> <!-- Replace with your module name -->
<class>Mage_Customer_Model_Entity_Setup</class>
</setup>
</profile_setup>
Tutaj dodamy nasz atrybut do formularza rejestracji klienta. W wersji 1.6.0 (+) użyty plik phtml to persistance/customer/register.phtml
, aw wersji 1.6.0 (-) użyty plik phtml to customer/form/register.phtml
Musimy więc otworzyć plik phtml, oparty na wersji magento i dodać ten kod do tagu .
<li>
<?php
$attribute = Mage::getModel('eav/config')->getAttribute('customer','school');
?>
<label for="school" class="<?php if($attribute->getIsRequired() == true){?>required<?php } ?>"><?php if($attribute->getIsRequired() == true){?><em>*</em><?php } ?><?php echo $this->__('School') ?></label>
<div class="input-box">
<select name="school" id="school" class="<?php if($attribute->getIsRequired() == true){?>required-entry<?php } ?>">
<?php
$options = $attribute->getSource()->getAllOptions();
foreach($options as $option){
?>
<option value='<?php echo $option['value']?>' <?php if($this->getFormData()->getSchool() == $option['value']){ echo 'selected="selected"';}?>><?php echo $this->__($option['label'])?></option>
<?php } ?>
</select>
</div>
</li>
Na Magento 1.4.2 (+), który, co jest wymagane w etapie rejestracji. Jeśli utworzysz tutaj użytkownika, powinieneś zobaczyć pole tekstowe szkoły w admin. Dla Magento 1.4.1 (-), musimy zrobić coś innego otworzyć plik moduły config.xml i dodać:
<global>
<fieldsets>
<customer_account>
<school><create>1</create><update>1</update><name>1</name></school>
</customer_account>
</fieldsets>
</global>
Gdy użytkownik stworzył swojego konta w sekcji Informacje MyAccount-> Konta powinien także móc edytować pole szkolne. W tym celu należy otworzyć plik Phtml customer/form/edit.phtml
i umieścić w kodzie w:
<?php
<li>
<?php
$attribute = Mage::getModel('eav/config')->getAttribute('customer','school');
?>
<label for="is_active" class="<?php if($attribute->getIsRequired() == true){?>required<?php } ?>"><?php if($attribute->getIsRequired() == true){?><em>*</em><?php } ?><?php echo $this->__('School') ?></label>
<div class="input-box">
<select name="school" id="school" class="<?php if($attribute->getIsRequired() == true){?>required-entry<?php } ?>">
<?php
$options = $attribute->getSource()->getAllOptions();
foreach($options as $option){
?>
<option value='<?php echo $option['value']?>' <?php if($this->getCustomer()->getSchool() == $option['value']){ echo 'selected="selected"';}?>><?php echo $this->__($option['label'])?></option>
<?php } ?>
</select>
</div>
</li>
Formularz rejestracyjny również pokazuje się na stronie transakcji w Magento. Aby można dodać pole tutaj, trzeba edytować checkout/onepage/billing.phtml
dla Magento wersji 1.6 (-) i persistant/checkout/onepage/billing.phtml
dla wersji Magento plików 1.6 (+), a następnie znaleźć kod:
<?php if(!$this->isCustomerLoggedIn()): ?>
wewnątrz tego czy warunek dodać pole
<li>
<li>
<?php
$attribute = Mage::getModel('eav/config')->getAttribute('customer','school');
?>
<label for="school" class="<?php if($attribute->getIsRequired() == true){?>required<?php } ?>"><?php if($attribute->getIsRequired() == true){?><em>*</em><?php } ?><?php echo $this->__('School') ?></label>
<div class="input-box">
<select name="billing[school]" id="school" class="<?php if($attribute->getIsRequired() == true){?>required-entry<?php } ?>">
<?php
$options = $attribute->getSource()->getAllOptions();
foreach($options as $option){
?>
<option value='<?php echo $option['value']?>'><?php echo $this->__($option['label'])?></option>
<?php } ?>
</select>
</div>
</li>
Następny otworzyć config.xml modułu lub dowolny inny plik config.xml dodać następujące wiersze:
<global>
<fieldsets>
<checkout_onepage_quote>
<customer_school>
<to_customer>school</to_customer>
</customer_school>
</checkout_onepage_quote>
<customer_account>
<school>
<to_quote>customer_school</to_quote>
</school>
</customer_account>
</fieldsets>
</global>
Następnie musimy wprowadzić pewne zmiany w tabeli ofert, np. tablica_sprzeda_tabela w programie magento. Jeśli masz moduł następnie utworzyć uaktualnienia wersję pliku sql i umieścić w tym kodzie:
$tablequote = $this->getTable('sales/quote');
$installer->run("
ALTER TABLE $tablequote ADD `customer_school` INT NOT NULL
");
Po wykonaniu tej czynności upewnij się, aby wyczyścić ci magento cache, specyficznie „Flush Magento Cache” i „Flush Pamięć podręczna pamięci masowej ". Teraz, gdy składasz zamówienie, klient jest tworzony z odpowiednim atrybutem szkoły.
Great Stuff Thanks! Dla 'source' => 'profile/entity_school' musimy stworzyć dla niego konkretny model, nie potrzebowałem go, ale dla innych byłoby fajnie umieścić taki przykład. – Shadowbob