00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 class Mage_Customer_Model_Customer extends Mage_Core_Model_Abstract
00033 {
00034 const XML_PATH_REGISTER_EMAIL_TEMPLATE = 'customer/create_account/email_template';
00035 const XML_PATH_REGISTER_EMAIL_IDENTITY = 'customer/create_account/email_identity';
00036 const XML_PATH_FORGOT_EMAIL_TEMPLATE = 'customer/password/forgot_email_template';
00037 const XML_PATH_FORGOT_EMAIL_IDENTITY = 'customer/password/forgot_email_identity';
00038 const XML_PATH_DEFAULT_EMAIL_DOMAIN = 'customer/create_account/email_domain';
00039 const XML_PATH_IS_CONFIRM = 'customer/create_account/confirm';
00040 const XML_PATH_CONFIRM_EMAIL_TEMPLATE = 'customer/create_account/email_confirmation_template';
00041 const XML_PATH_CONFIRMED_EMAIL_TEMPLATE = 'customer/create_account/email_confirmed_template';
00042
00043 const EXCEPTION_EMAIL_NOT_CONFIRMED = 1;
00044 const EXCEPTION_INVALID_EMAIL_OR_PASSWORD = 2;
00045
00046 const SUBSCRIBED_YES = 'yes';
00047 const SUBSCRIBED_NO = 'no';
00048
00049 protected $_eventPrefix = 'customer';
00050 protected $_eventObject = 'customer';
00051 protected $_addresses = null;
00052 protected $_errors = array();
00053 protected $_attributes;
00054
00055
00056
00057
00058
00059
00060 protected $_isDeleteable = true;
00061
00062
00063
00064
00065
00066
00067 protected $_isReadonly = false;
00068
00069
00070 private static $_isConfirmationRequired;
00071
00072 function _construct()
00073 {
00074 $this->_init('customer/customer');
00075 }
00076
00077
00078
00079
00080
00081
00082 public function getSharingConfig()
00083 {
00084 return Mage::getSingleton('customer/config_share');
00085
00086 }
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 public function authenticate($login, $password)
00097 {
00098 $this->loadByEmail($login);
00099 if ($this->getConfirmation() && $this->isConfirmationRequired()) {
00100 throw new Exception(Mage::helper('customer')->__('This account is not confirmed.'), self::EXCEPTION_EMAIL_NOT_CONFIRMED);
00101 }
00102 if (!$this->validatePassword($password)) {
00103 throw new Exception(Mage::helper('customer')->__('Invalid login or password.'), self::EXCEPTION_INVALID_EMAIL_OR_PASSWORD);
00104 }
00105 Mage::dispatchEvent('customer_customer_authenticated', array(
00106 'model' => $this,
00107 'password' => $password,
00108 ));
00109 return true;
00110 }
00111
00112
00113
00114
00115
00116
00117
00118 public function loadByEmail($customerEmail)
00119 {
00120 $this->_getResource()->loadByEmail($this, $customerEmail);
00121 return $this;
00122 }
00123
00124
00125
00126
00127
00128
00129
00130 protected function _beforeSave()
00131 {
00132 parent::_beforeSave();
00133
00134 $storeId = $this->getStoreId();
00135 if (is_null($storeId)) {
00136 $this->setStoreId(Mage::app()->getStore()->getId());
00137 }
00138
00139 $this->getGroupId();
00140 return $this;
00141 }
00142
00143
00144
00145
00146
00147
00148
00149 public function changePassword($newPassword)
00150 {
00151 $this->_getResource()->changePassword($this, $newPassword);
00152 return $this;
00153 }
00154
00155
00156
00157
00158
00159
00160 public function getName()
00161 {
00162 $name = '';
00163 if ($this->getPrefix()) {
00164 $name .= $this->getPrefix() . ' ';
00165 }
00166 $name .= $this->getFirstname();
00167 if ($this->getMiddlename()) {
00168 $name .= ' ' . $this->getMiddlename();
00169 }
00170 $name .= ' ' . $this->getLastname();
00171 if ($this->getSuffix()) {
00172 $name .= ' ' . $this->getSuffix();
00173 }
00174 return $name;
00175 }
00176
00177
00178
00179
00180
00181
00182
00183 public function addAddress(Mage_Customer_Model_Address $address)
00184 {
00185 $this->getAddresses();
00186 $this->_addresses[] = $address;
00187 return $this;
00188 }
00189
00190
00191
00192
00193
00194
00195
00196 public function getAddressById($addressId)
00197 {
00198 return Mage::getModel('customer/address')
00199 ->load($addressId);
00200 }
00201
00202
00203
00204
00205
00206
00207 public function getAddressCollection()
00208 {
00209 return Mage::getResourceModel('customer/address_collection');
00210 }
00211
00212
00213
00214
00215
00216
00217 public function getAddresses()
00218 {
00219 if (is_null($this->_addresses)) {
00220 $this->_addresses = array();
00221 $collection = $this->getAddressCollection()
00222 ->setCustomerFilter($this)
00223 ->addAttributeToSelect('*')
00224 ->load();
00225 foreach ($collection as $address) {
00226 $this->_addresses[] = $address;
00227 }
00228 }
00229
00230 return $this->_addresses;
00231 }
00232
00233
00234
00235
00236
00237
00238 public function getAttributes()
00239 {
00240 if (null === $this->_attributes) {
00241 $this->_attributes = $this->_getResource()
00242 ->loadAllAttributes($this)
00243 ->getSortedAttributes();
00244 }
00245 return $this->_attributes;
00246 }
00247
00248 public function getAttribute($attributeCode)
00249 {
00250 $this->getAttributes();
00251 if (isset($this->_attributes[$attributeCode])) {
00252 return $this->_attributes[$attributeCode];
00253 }
00254 return null;
00255 }
00256
00257
00258
00259
00260
00261
00262
00263 public function setPassword($password)
00264 {
00265 $this->setData('password', $password);
00266 $this->setPasswordHash($this->hashPassword($password));
00267 return $this;
00268 }
00269
00270
00271
00272
00273
00274
00275
00276 public function hashPassword($password, $salt=null)
00277 {
00278 return Mage::helper('core')->getHash($password, !is_null($salt) ? $salt : 2);
00279 }
00280
00281
00282
00283
00284
00285
00286
00287 public function generatePassword($length=6)
00288 {
00289 return substr(md5(uniqid(rand(), true)), 0, $length);
00290 }
00291
00292
00293
00294
00295
00296
00297
00298 public function validatePassword($password)
00299 {
00300 if (!($hash = $this->getPasswordHash())) {
00301 return false;
00302 }
00303 return Mage::helper('core')->validateHash($password, $hash);
00304 }
00305
00306
00307
00308
00309
00310
00311
00312
00313 public function encryptPassword($password)
00314 {
00315 return Mage::helper('core')->encrypt($password);
00316 }
00317
00318
00319
00320
00321
00322
00323
00324 public function decryptPassword($password)
00325 {
00326 return Mage::helper('core')->decrypt($password);
00327 }
00328
00329
00330
00331
00332
00333
00334
00335 public function getPrimaryAddress($attributeCode)
00336 {
00337 $addressId = $this->getData($attributeCode);
00338 $primaryAddress = false;
00339 if ($addressId) {
00340 foreach ($this->getAddresses() as $address) {
00341 if ($addressId == $address->getId()) {
00342 return $address;
00343 }
00344 }
00345 }
00346 return $primaryAddress;
00347 }
00348
00349
00350
00351
00352
00353
00354 public function getPrimaryBillingAddress()
00355 {
00356 return $this->getPrimaryAddress('default_billing');
00357 }
00358
00359 public function getDefaultBillingAddress()
00360 {
00361 return $this->getPrimaryBillingAddress();
00362 }
00363
00364
00365
00366
00367
00368
00369 public function getPrimaryShippingAddress()
00370 {
00371 return $this->getPrimaryAddress('default_shipping');
00372 }
00373
00374 public function getDefaultShippingAddress()
00375 {
00376 return $this->getPrimaryShippingAddress();
00377 }
00378
00379
00380
00381
00382
00383
00384 public function getPrimaryAddressIds()
00385 {
00386 $ids = array();
00387 if ($this->getDefaultBilling()) {
00388 $ids[] = $this->getDefaultBilling();
00389 }
00390 if ($this->getDefaultShipping()) {
00391 $ids[] = $this->getDefaultShipping();
00392 }
00393 return $ids;
00394 }
00395
00396
00397
00398
00399
00400
00401 public function getPrimaryAddresses()
00402 {
00403 $addresses = array();
00404 $primaryBilling = $this->getPrimaryBillingAddress();
00405 if ($primaryBilling) {
00406 $addresses[] = $primaryBilling;
00407 $primaryBilling->setIsPrimaryBilling(true);
00408 }
00409
00410 $primaryShipping = $this->getPrimaryShippingAddress();
00411 if ($primaryShipping) {
00412 if ($primaryBilling->getId() == $primaryShipping->getId()) {
00413 $primaryBilling->setIsPrimaryShipping(true);
00414 }
00415 else {
00416 $primaryShipping->setIsPrimaryShipping(true);
00417 $addresses[] = $primaryShipping;
00418 }
00419 }
00420 return $addresses;
00421 }
00422
00423
00424
00425
00426
00427
00428 public function getAdditionalAddresses()
00429 {
00430 $addresses = array();
00431 $primatyIds = $this->getPrimaryAddressIds();
00432 foreach ($this->getAddresses() as $address) {
00433 if (!in_array($address->getId(), $primatyIds)) {
00434 $addresses[] = $address;
00435 }
00436 }
00437 return $addresses;
00438 }
00439
00440 public function isAddressPrimary(Mage_Customer_Model_Address $address)
00441 {
00442 if (!$address->getId()) {
00443 return false;
00444 }
00445 return ($address->getId() == $this->getDefaultBilling()) || ($address->getId() == $this->getDefaultShipping());
00446 }
00447
00448
00449
00450
00451
00452
00453 public function sendNewAccountEmail($type = 'registered', $backUrl = '')
00454 {
00455 $types = array(
00456 'registered' => self::XML_PATH_REGISTER_EMAIL_TEMPLATE,
00457 'confirmed' => self::XML_PATH_CONFIRMED_EMAIL_TEMPLATE,
00458 'confirmation' => self::XML_PATH_CONFIRM_EMAIL_TEMPLATE,
00459 );
00460 if (!isset($types[$type])) {
00461 throw new Exception(Mage::helper('customer')->__('Wrong transactional account email type.'));
00462 }
00463
00464 $translate = Mage::getSingleton('core/translate');
00465
00466 $translate->setTranslateInline(false);
00467
00468 $storeId = $this->getStoreId();
00469 if ($this->getWebsiteId() != '0' && $storeId == '0') {
00470 $storeIds = Mage::app()->getWebsite($this->getWebsiteId())->getStoreIds();
00471 reset($storeIds);
00472 $storeId = current($storeIds);
00473 }
00474
00475 Mage::getModel('core/email_template')
00476 ->setDesignConfig(array('area'=>'frontend', 'store'=>$storeId))
00477 ->sendTransactional(
00478 Mage::getStoreConfig($types[$type]),
00479 Mage::getStoreConfig(self::XML_PATH_REGISTER_EMAIL_IDENTITY),
00480 $this->getEmail(),
00481 $this->getName(),
00482 array('customer' => $this, 'back_url' => $backUrl));
00483
00484 $translate->setTranslateInline(true);
00485
00486 return $this;
00487 }
00488
00489
00490
00491
00492
00493
00494 public function isConfirmationRequired()
00495 {
00496 if ($this->canSkipConfirmation()) {
00497 return false;
00498 }
00499 if (null === self::$_isConfirmationRequired) {
00500 self::$_isConfirmationRequired = 1 == Mage::getStoreConfig(self::XML_PATH_IS_CONFIRM, ($this->getStoreId() ? $this->getStoreId() : null));
00501 }
00502 return self::$_isConfirmationRequired;
00503 }
00504
00505 public function getRandomConfirmationKey()
00506 {
00507 return md5(uniqid());
00508 }
00509
00510
00511
00512
00513
00514
00515 public function sendPasswordReminderEmail()
00516 {
00517 $translate = Mage::getSingleton('core/translate');
00518
00519 $translate->setTranslateInline(false);
00520
00521 $storeId = $this->getStoreId();
00522 if ($this->getWebsiteId() != '0' && $storeId == '0') {
00523 $storeIds = Mage::app()->getWebsite($this->getWebsiteId())->getStoreIds();
00524 reset($storeIds);
00525 $storeId = current($storeIds);
00526 }
00527
00528 Mage::getModel('core/email_template')
00529 ->setDesignConfig(array('area'=>'frontend', 'store'=>$storeId))
00530 ->sendTransactional(
00531 Mage::getStoreConfig(self::XML_PATH_FORGOT_EMAIL_TEMPLATE),
00532 Mage::getStoreConfig(self::XML_PATH_FORGOT_EMAIL_IDENTITY),
00533 $this->getEmail(),
00534 $this->getName(),
00535 array('customer'=>$this)
00536 );
00537
00538 $translate->setTranslateInline(true);
00539
00540 return $this;
00541 }
00542
00543
00544
00545
00546
00547
00548 public function getGroupId()
00549 {
00550 if (!$this->getData('group_id')) {
00551 $storeId = $this->getStoreId() ? $this->getStoreId() : Mage::app()->getStore()->getId();
00552 $this->setData('group_id', Mage::getStoreConfig(Mage_Customer_Model_Group::XML_PATH_DEFAULT_ID, $storeId));
00553 }
00554 return $this->getData('group_id');
00555 }
00556
00557
00558
00559
00560
00561
00562 public function getTaxClassId()
00563 {
00564 if (!$this->getData('tax_class_id')) {
00565 $this->setTaxClassId(Mage::getModel('customer/group')->getTaxClassId($this->getGroupId()));
00566 }
00567 return $this->getData('tax_class_id');
00568 }
00569
00570
00571
00572
00573
00574
00575
00576 public function isInStore($store)
00577 {
00578 if ($store instanceof Mage_Core_Model_Store) {
00579 $storeId = $store->getId();
00580 }
00581 else {
00582 $storeId = $store;
00583 }
00584 $availableStores = $this->getSharedStoreIds();
00585 return in_array($storeId, $availableStores);
00586 }
00587
00588
00589
00590
00591
00592
00593 public function getStore()
00594 {
00595 return Mage::app()->getStore($this->getStoreId());
00596 }
00597
00598
00599
00600
00601
00602
00603 public function getSharedStoreIds()
00604 {
00605 $ids = $this->_getData('shared_store_ids');
00606 if (is_null($ids)) {
00607 $ids = array();
00608 if ((bool)$this->getSharingConfig()->isWebsiteScope()) {
00609 $ids = $this->getStore()->getWebsite()->getStoreIds();
00610 }
00611 else {
00612 foreach (Mage::app()->getStores() as $store) {
00613 $ids[] = $store->getId();
00614 }
00615 }
00616 $this->setData('shared_store_ids', $ids);
00617 }
00618 return $ids;
00619 }
00620
00621
00622
00623
00624
00625
00626 public function getSharedWebsiteIds()
00627 {
00628 $ids = $this->_getData('shared_website_ids');
00629 if (is_null($ids)) {
00630 $ids = array();
00631 if ((bool)$this->getSharingConfig()->isWebsiteScope()) {
00632 $ids[] = $this->getWebsiteId();
00633 }
00634 else {
00635 foreach (Mage::app()->getWebsites() as $website) {
00636 $ids[] = $website->getId();
00637 }
00638 }
00639 $this->setData('shared_website_ids', $ids);
00640 }
00641 return $ids;
00642 }
00643
00644
00645
00646
00647
00648
00649
00650 public function setStore(Mage_Core_Model_Store $store)
00651 {
00652 $this->setStoreId($store->getId());
00653 return $this;
00654 }
00655
00656
00657
00658
00659
00660
00661 public function validate()
00662 {
00663 $errors = array();
00664
00665 if (!Zend_Validate::is( trim($this->getFirstname()) , 'NotEmpty')) {
00666 $errors[] = Mage::helper('customer')->__('First name can\'t be empty');
00667 }
00668
00669 if (!Zend_Validate::is( trim($this->getLastname()) , 'NotEmpty')) {
00670 $errors[] = Mage::helper('customer')->__('Last name can\'t be empty');
00671 }
00672
00673 if (!Zend_Validate::is($this->getEmail(), 'EmailAddress')) {
00674 $errors[] = Mage::helper('customer')->__('Invalid email address "%s"', $this->getEmail());
00675 }
00676
00677 $password = $this->getPassword();
00678 if (!$this->getId() && !Zend_Validate::is($password , 'NotEmpty')) {
00679 $errors[] = Mage::helper('customer')->__('Password can\'t be empty');
00680 }
00681 if ($password && !Zend_Validate::is($password, 'StringLength', array(6))) {
00682 $errors[] = Mage::helper('customer')->__('Password minimal length must be more %s', 6);
00683 }
00684 $confirmation = $this->getConfirmation();
00685 if ($password != $confirmation) {
00686 $errors[] = Mage::helper('customer')->__('Please make sure your passwords match.');
00687 }
00688
00689 if (('req' === Mage::helper('customer/address')->getConfig('dob_show'))
00690 && '' == trim($this->getDob())) {
00691 $errors[] = Mage::helper('customer')->__('Date of Birth is required.');
00692 }
00693 if (('req' === Mage::helper('customer/address')->getConfig('taxvat_show'))
00694 && '' == trim($this->getTaxvat())) {
00695 $errors[] = Mage::helper('customer')->__('TAX/VAT number is required.');
00696 }
00697
00698 if (empty($errors)) {
00699 return true;
00700 }
00701 return $errors;
00702 }
00703
00704
00705
00706
00707
00708
00709
00710 public function importFromTextArray(array $row)
00711 {
00712 $this->resetErrors();
00713 $hlp = Mage::helper('customer');
00714 $line = $row['i'];
00715 $row = $row['row'];
00716
00717 $regions = Mage::getResourceModel('directory/region_collection');
00718
00719
00720 $website = Mage::getModel('core/website')->load($row['website_code'], 'code');
00721
00722 if (!$website->getId()) {
00723 $this->addError($hlp->__('Invalid website, skipping the record, line: %s', $line));
00724
00725 } else {
00726 $row['website_id'] = $website->getWebsiteId();
00727 $this->setWebsiteId($row['website_id']);
00728 }
00729
00730
00731 if (empty($row['email'])) {
00732 $this->addError($hlp->__('Missing email, skipping the record, line: %s', $line));
00733 } else {
00734 $this->loadByEmail($row['email']);
00735 }
00736
00737 if (empty($row['entity_id'])) {
00738 if ($this->getData('entity_id')) {
00739 $this->addError($hlp->__('Customer email (%s) already exists, skipping the record , line: %s', $row['email'], $line));
00740 }
00741 } else {
00742 if ($row['entity_id'] != $this->getData('entity_id')) {
00743 $this->addError($hlp->__('CustomerID and email didn\'t match, skipping the record , line: %s', $line));
00744 } else {
00745 $this->unsetData();
00746 $this->load($row['entity_id']);
00747 if (isset($row['store_view'])) {
00748 $storeId = Mage::app()->getStore($row['store_view'])->getId();
00749 if ($storeId) $this->setStoreId($storeId);
00750 }
00751 }
00752 }
00753
00754 if (empty($row['website_code'])) {
00755 $this->addError($hlp->__('Missing website, skipping the record, line: %s', $line));
00756 }
00757
00758 if (empty($row['group'])) {
00759 $row['group'] = 'General';
00760 }
00761
00762 if (empty($row['firstname'])) {
00763 $this->addError($hlp->__('Missing firstname, skipping the record, line: %s', $line));
00764 }
00765 if (empty($row['lastname'])) {
00766 $this->addError($hlp->__('Missing lastname, skipping the record, line: %s', $line));
00767 }
00768
00769 if (!empty($row['password_new'])) {
00770 $this->setPassword($row['password_new']);
00771 unset($row['password_new']);
00772 if (!empty($row['password_hash'])) unset($row['password_hash']);
00773 }
00774
00775 if ($errors = $this->getErrors()) {
00776 $this->unsetData();
00777 $this->printError(join("<br />",$errors));
00778 return;
00779 }
00780
00781 foreach ($row as $field=>$value) {
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797 $this->setData($field, $value);
00798 }
00799
00800 if (!$this->validateAddress($row, 'billing')) {
00801 $this->printError($hlp->__('Invalid billing address for (%s)', $row['email']), $line);
00802 } else {
00803
00804 $billingAddress = $this->getPrimaryBillingAddress();
00805 if (!$billingAddress instanceof Mage_Customer_Model_Address) {
00806 $billingAddress = new Mage_Customer_Model_Address();
00807 }
00808
00809 $regions->addRegionNameFilter($row['billing_region'])->load();
00810 if ($regions) foreach($regions as $region) {
00811 $regionId = $region->getId();
00812 }
00813
00814 $billingAddress->setFirstname($row['firstname']);
00815 $billingAddress->setLastname($row['lastname']);
00816 $billingAddress->setCity($row['billing_city']);
00817 $billingAddress->setRegion($row['billing_region']);
00818 if (isset($regionId)) $billingAddress->setRegionId($regionId);
00819 $billingAddress->setCountryId($row['billing_country']);
00820 $billingAddress->setPostcode($row['billing_postcode']);
00821 if (isset($row['billing_street2'])) {
00822 $billingAddress->setStreet(array($row['billing_street1'],$row['billing_street2']));
00823 } else {
00824 $billingAddress->setStreet(array($row['billing_street1']));
00825 }
00826 if (isset($row['billing_telephone'])) {
00827 $billingAddress->setTelephone($row['billing_telephone']);
00828 }
00829
00830 if (!$billingAddress->getId()) {
00831 $billingAddress->setIsDefaultBilling(true);
00832 if ($this->getDefaultBilling()) {
00833 $this->setData('default_billing', '');
00834 }
00835 $this->addAddress($billingAddress);
00836 }
00837 }
00838
00839 if (!$this->validateAddress($row, 'shipping')) {
00840 $this->printError($hlp->__('Invalid shipping address for (%s)', $row['email']), $line);
00841 } else {
00842
00843 $shippingAddress = $this->getPrimaryShippingAddress();
00844 if (!$shippingAddress instanceof Mage_Customer_Model_Address) {
00845 $shippingAddress = new Mage_Customer_Model_Address();
00846 }
00847
00848 $regions->addRegionNameFilter($row['shipping_region'])->load();
00849
00850 if ($regions) foreach($regions as $region) {
00851 $regionId = $region->getId();
00852 }
00853
00854 $shippingAddress->setFirstname($row['firstname']);
00855 $shippingAddress->setLastname($row['lastname']);
00856 $shippingAddress->setCity($row['shipping_city']);
00857 $shippingAddress->setRegion($row['shipping_region']);
00858 if (isset($regionId)) $shippingAddress->setRegionId($regionId);
00859 $shippingAddress->setCountryId($row['shipping_country']);
00860 $shippingAddress->setPostcode($row['shipping_postcode']);
00861 if (isset($row['shipping_street2'])) {
00862 $shippingAddress->setStreet(array($row['shipping_street1'], $row['shipping_street2']));
00863 } else {
00864 $shippingAddress->setStreet(array($row['shipping_street1']));
00865 }
00866 if (!empty($row['shipping_telephone'])) {
00867 $shippingAddress->setTelephone($row['shipping_telephone']);
00868 }
00869
00870 if (!$shippingAddress->getId()) {
00871 $shippingAddress->setIsDefaultShipping(true);
00872 $this->addAddress($shippingAddress);
00873 }
00874
00875 }
00876 if (!empty($row['is_subscribed'])) {
00877 $this->setIsSubscribed(strtolower($row['is_subscribed'])==self::SUBSCRIBED_YES ? 1 : 0);
00878 }
00879 unset($row);
00880 return $this;
00881 }
00882
00883 function unsetSubscription()
00884 {
00885 if (isset($this->_isSubscribed)) {
00886 unset($this->_isSubscribed);
00887 }
00888 }
00889
00890 function cleanAllAddresses() {
00891 $this->_addresses = null;
00892 }
00893
00894 function addError($error)
00895 {
00896 $this->_errors[] = $error;
00897 }
00898
00899 function getErrors()
00900 {
00901 return $this->_errors;
00902 }
00903
00904 function resetErrors()
00905 {
00906 $this->_errors = array();
00907 }
00908
00909 function printError($error, $line = null)
00910 {
00911 if ($error == null) return false;
00912 $img = 'error_msg_icon.gif';
00913 $liStyle = 'background-color:#FDD; ';
00914 echo '<li style="'.$liStyle.'">';
00915 echo '<img src="'.Mage::getDesign()->getSkinUrl('images/'.$img).'" class="v-middle"/>';
00916 echo $error;
00917 if ($line) {
00918 echo '<small>, Line: <b>'.$line.'</b></small>';
00919 }
00920 echo "</li>";
00921 }
00922
00923 function validateAddress(array $data, $type = 'billing')
00924 {
00925 $fields = array('city',
00926 'country', 'postcode',
00927 'telephone', 'street1');
00928 $usca = array('US', 'CA');
00929 $prefix = $type ? $type.'_':'';
00930
00931 if ($data) {
00932 foreach($fields as $field) {
00933 if (!isset($data[$prefix.$field])) {
00934 return false;
00935 }
00936 if ($field == 'country'
00937 && in_array(strtolower($data[$prefix.$field]), array('US', 'CA'))) {
00938
00939 if (!isset($data[$prefix.'region'])) {
00940 return false;
00941 }
00942
00943 $region = Mage::getModel('directory/region')
00944 ->loadByName($data[$prefix.'region']);
00945 if (!$region->getId()) {
00946 return false;
00947 }
00948 unset($region);
00949 }
00950 }
00951 unset($data);
00952 return true;
00953 }
00954 return false;
00955 }
00956
00957 protected function _beforeDelete()
00958 {
00959 $this->_protectFromNonAdmin();
00960 return parent::_beforeDelete();
00961 }
00962
00963
00964
00965
00966
00967
00968 public function getCreatedAtTimestamp()
00969 {
00970 if ($date = $this->getCreatedAt()) {
00971 return $this->_getResource()->mktime($date);
00972 }
00973 return null;
00974 }
00975
00976
00977
00978
00979
00980
00981 public function reset()
00982 {
00983 $this->setData(array());
00984 $this->setOrigData();
00985 $this->_attributes = null;
00986
00987 return $this;
00988 }
00989
00990
00991
00992
00993
00994
00995 public function isDeleteable()
00996 {
00997 return $this->_isDeleteable;
00998 }
00999
01000
01001
01002
01003
01004
01005
01006 public function setIsDeleteable($value)
01007 {
01008 $this->_isDeleteable = (boolean) $value;
01009 return $this;
01010 }
01011
01012
01013
01014
01015
01016
01017 public function isReadonly()
01018 {
01019 return $this->_isReadonly;
01020 }
01021
01022
01023
01024
01025
01026
01027
01028 public function setIsReadonly($value)
01029 {
01030 $this->_isReadonly = (boolean) $value;
01031 return $this;
01032 }
01033
01034
01035
01036
01037
01038
01039 public function canSkipConfirmation()
01040 {
01041 return $this->getId() && $this->hasSkipConfirmationIfEmail()
01042 && strtolower($this->getSkipConfirmationIfEmail()) === strtolower($this->getEmail());
01043 }
01044 }