Advertisement
Guest User

Untitled

a guest
Mar 10th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.90 KB | None | 0 0
  1. <?php
  2.  
  3. class SAGO_CoreModifications_Customer_AccountController extends Mage_Customer_AccountController {
  4.  
  5.  
  6. /**
  7. * Get Customer Model. Overrides Magento function to setup group depending on customer selection.
  8. *
  9. * @return Mage_Customer_Model_Customer
  10. */
  11. protected function _getCustomer()
  12. {
  13. $customer = $this->_getFromRegistry('current_customer');
  14. if (!$customer) {
  15. $customer = $this->_getModel('customer/customer')->setId(null);
  16. }
  17. if ($this->getRequest()->getParam('is_subscribed', false)) {
  18. $customer->setIsSubscribed(1);
  19. }
  20. /**
  21. * Initialize customer group id
  22. */
  23.  
  24. if($this->getRequest()->getPost('group_id')){
  25. $customer->setGroupId($this->getRequest()->getPost('group_id'));
  26. } else {
  27. $customer->getGroupId();
  28. }
  29.  
  30. return $customer;
  31. }
  32. }
  33.  
  34. <?php
  35. /**
  36. * Copyright © Magento, Inc. All rights reserved.
  37. * See COPYING.txt for license details.
  38. */
  39.  
  40. // @codingStandardsIgnoreFile
  41.  
  42. /** @var MagentoCustomerBlockFormRegister $block */
  43. ?>
  44. <?= $block->getChildHtml('form_fields_before') ?>
  45. <?php /* Extensions placeholder */ ?>
  46. <?= $block->getChildHtml('customer.form.register.extra') ?>
  47. <p>questo &egrave; l'override;</p>
  48. <form class="form create account form-create-account" action="<?= $block->escapeUrl($block->getPostActionUrl()) ?>" method="post" id="form-validate" enctype="multipart/form-data" autocomplete="off">
  49. <?= /* @noEscape */ $block->getBlockHtml('formkey'); ?>
  50. <fieldset class="fieldset create info">
  51. <legend class="legend"><span><?= $block->escapeHtml(__('Personal Information')) ?></span></legend><br>
  52. <input type="hidden" name="success_url" value="<?= $block->escapeUrl($block->getSuccessUrl()) ?>">
  53. <input type="hidden" name="error_url" value="<?= $block->escapeUrl($block->getErrorUrl()) ?>">
  54. <?= $block->getLayout()->createBlock('MagentoCustomerBlockWidgetName')->setObject($block->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?>
  55. <?php if ($block->isNewsletterEnabled()): ?>
  56. <div class="field choice newsletter">
  57. <input type="checkbox" name="is_subscribed" title="<?= $block->escapeHtmlAttr(__('Sign Up for Newsletter')) ?>" value="1" id="is_subscribed"<?php if ($block->getFormData()->getIsSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox">
  58. <label for="is_subscribed" class="label"><span><?= $block->escapeHtml(__('Sign Up for Newsletter')) ?></span></label>
  59. </div>
  60. <select class="radiogroup">
  61. <option name="group_id" class="user_type" value="4" type="radio" tabindex="1">
  62. <label for="group_id_4">Privato</label>
  63. </option>
  64. <option name="group_id" class="user_type" value="2" checked="checked" type="radio" tabindex="2">
  65. <label for="group_id_2">Wholesale</label>
  66. </option>
  67. </select>
  68. <?= $block->getChildHtml('customer.form.register.newsletter') ?>
  69. <?php endif ?>
  70.  
  71. <?php $_dob = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetDob') ?>
  72. <?php if ($_dob->isEnabled()): ?>
  73. <?= $_dob->setDate($block->getFormData()->getDob())->toHtml() ?>
  74. <?php endif ?>
  75.  
  76. <?php $_taxvat = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetTaxvat') ?>
  77. <?php if ($_taxvat->isEnabled()): ?>
  78. <?= $_taxvat->setTaxvat($block->getFormData()->getTaxvat())->toHtml() ?>
  79. <?php endif ?>
  80.  
  81. <?php $_gender = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetGender') ?>
  82. <?php if ($_gender->isEnabled()): ?>
  83. <?= $_gender->setGender($block->getFormData()->getGender())->toHtml() ?>
  84. <?php endif ?>
  85. </fieldset>
  86. <?php if ($block->getShowAddressFields()): ?>
  87. <fieldset class="fieldset address">
  88. <legend class="legend"><span><?= $block->escapeHtml(__('Address Information')) ?></span></legend><br>
  89. <input type="hidden" name="create_address" value="1" />
  90.  
  91. <?php $_company = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetCompany') ?>
  92. <?php if ($_company->isEnabled()): ?>
  93. <?= $_company->setCompany($block->getFormData()->getCompany())->toHtml() ?>
  94. <?php endif ?>
  95.  
  96. <?php $_telephone = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetTelephone') ?>
  97. <?php if ($_telephone->isEnabled()): ?>
  98. <?= $_telephone->setTelephone($block->getFormData()->getTelephone())->toHtml() ?>
  99. <?php endif ?>
  100.  
  101. <?php $_fax = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetFax') ?>
  102. <?php if ($_fax->isEnabled()): ?>
  103. <?= $_fax->setFax($block->getFormData()->getFax())->toHtml() ?>
  104. <?php endif ?>
  105.  
  106. <?php $_streetValidationClass = $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('street'); ?>
  107.  
  108. <div class="field street required">
  109. <label for="street_1" class="label"><span><?= $block->escapeHtml(__('Street Address')) ?></span></label>
  110. <div class="control">
  111. <input type="text" name="street[]" value="<?= $block->escapeHtmlAttr($block->getFormData()->getStreet(0)) ?>" title="<?= $block->escapeHtmlAttr(__('Street Address')) ?>" id="street_1" class="input-text <?= $block->escapeHtmlAttr($_streetValidationClass) ?>">
  112. <div class="nested">
  113. <?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
  114. <?php for ($_i = 2, $_n = $this->helper('MagentoCustomerHelperAddress')->getStreetLines(); $_i <= $_n; $_i++): ?>
  115. <div class="field additional">
  116. <label class="label" for="street_<?= /* @noEscape */ $_i ?>">
  117. <span><?= $block->escapeHtml(__('Address')) ?></span>
  118. </label>
  119. <div class="control">
  120. <input type="text" name="street[]" value="<?= $block->escapeHtml($block->getFormData()->getStreetLine($_i - 1)) ?>" title="<?= $block->escapeHtmlAttr(__('Street Address %1', $_i)) ?>" id="street_<?= /* @noEscape */ $_i ?>" class="input-text <?= $block->escapeHtmlAttr($_streetValidationClass) ?>">
  121. </div>
  122. </div>
  123. <?php endfor; ?>
  124. </div>
  125. </div>
  126. </div>
  127.  
  128. <div class="field required">
  129. <label for="city" class="label"><span><?= $block->escapeHtml(__('City')) ?></span></label>
  130. <div class="control">
  131. <input type="text" name="city" value="<?= $block->escapeHtmlAttr($block->getFormData()->getCity()) ?>" title="<?= $block->escapeHtmlAttr(__('City')) ?>" class="input-text <?= $block->escapeHtmlAttr($this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('city')) ?>" id="city">
  132. </div>
  133. </div>
  134.  
  135. <div class="field region required">
  136. <label for="region_id" class="label"><span><?= $block->escapeHtml(__('State/Province')) ?></span></label>
  137. <div class="control">
  138. <select id="region_id" name="region_id" title="<?= $block->escapeHtmlAttr(__('State/Province')) ?>" class="validate-select" style="display:none;">
  139. <option value=""><?= $block->escapeHtml(__('Please select a region, state or province.')) ?></option>
  140. </select>
  141. <input type="text" id="region" name="region" value="<?= $block->escapeHtml($block->getRegion()) ?>" title="<?= $block->escapeHtmlAttr(__('State/Province')) ?>" class="input-text <?= $block->escapeHtmlAttr($this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('region')) ?>" style="display:none;">
  142. </div>
  143. </div>
  144.  
  145. <div class="field zip required">
  146. <label for="zip" class="label"><span><?= $block->escapeHtml(__('Zip/Postal Code')) ?></span></label>
  147. <div class="control">
  148. <input type="text" name="postcode" value="<?= $block->escapeHtmlAttr($block->getFormData()->getPostcode()) ?>" title="<?= $block->escapeHtmlAttr(__('Zip/Postal Code')) ?>" id="zip" class="input-text validate-zip-international <?= $block->escapeHtmlAttr($this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('postcode')) ?>">
  149. </div>
  150. </div>
  151.  
  152. <div class="field country required">
  153. <label for="country" class="label"><span><?= $block->escapeHtml(__('Country')) ?></span></label>
  154. <div class="control">
  155. <?= $block->getCountryHtmlSelect() ?>
  156. </div>
  157. </div>
  158. <?php $addressAttributes = $block->getChildBlock('customer_form_address_user_attributes');?>
  159. <?php if ($addressAttributes): ?>
  160. <?php $addressAttributes->setEntityType('customer_address'); ?>
  161. <?php $addressAttributes->setFieldIdFormat('address:%1$s')->setFieldNameFormat('address[%1$s]');?>
  162. <?php $block->restoreSessionData($addressAttributes->getMetadataForm(), 'address');?>
  163. <?= $addressAttributes->setShowContainer(false)->toHtml() ?>
  164. <?php endif;?>
  165. <input type="hidden" name="default_billing" value="1">
  166. <input type="hidden" name="default_shipping" value="1">
  167. </fieldset>
  168.  
  169. <?php endif; ?>
  170. <fieldset class="fieldset create account" data-hasrequired="<?= $block->escapeHtmlAttr(__('* Required Fields')) ?>">
  171. <legend class="legend"><span><?= $block->escapeHtml(__('Sign-in Information')) ?></span></legend><br>
  172. <div class="field required">
  173. <label for="email_address" class="label"><span><?= $block->escapeHtml(__('Email')) ?></span></label>
  174. <div class="control">
  175. <input type="email" name="email" autocomplete="email" id="email_address" value="<?= $block->escapeHtmlAttr($block->getFormData()->getEmail()) ?>" title="<?= $block->escapeHtmlAttr(__('Email')) ?>" class="input-text" data-validate="{required:true, 'validate-email':true}">
  176. </div>
  177. </div>
  178. <div class="field password required">
  179. <label for="password" class="label"><span><?= $block->escapeHtml(__('Password')) ?></span></label>
  180. <div class="control">
  181. <input type="password" name="password" id="password"
  182. title="<?= $block->escapeHtmlAttr(__('Password')) ?>"
  183. class="input-text"
  184. data-password-min-length="<?= $block->escapeHtmlAttr($block->getMinimumPasswordLength()) ?>"
  185. data-password-min-character-sets="<?= $block->escapeHtmlAttr($block->getRequiredCharacterClassesNumber()) ?>"
  186. data-validate="{required:true, 'validate-customer-password':true}"
  187. autocomplete="off">
  188. <div id="password-strength-meter-container" data-role="password-strength-meter" aria-live="polite">
  189. <div id="password-strength-meter" class="password-strength-meter">
  190. <?= $block->escapeHtml(__('Password Strength')) ?>:
  191. <span id="password-strength-meter-label" data-role="password-strength-meter-label">
  192. <?= $block->escapeHtml(__('No Password')) ?>
  193. </span>
  194. </div>
  195. </div>
  196. </div>
  197.  
  198. </div>
  199. <div class="field confirmation required">
  200. <label for="password-confirmation" class="label"><span><?= $block->escapeHtml(__('Confirm Password')) ?></span></label>
  201. <div class="control">
  202. <input type="password" name="password_confirmation" title="<?= $block->escapeHtmlAttr(__('Confirm Password')) ?>" id="password-confirmation" class="input-text" data-validate="{required:true, equalTo:'#password'}" autocomplete="off">
  203. </div>
  204. </div>
  205. <?= $block->getChildHtml('form_additional_info') ?>
  206. </fieldset>
  207. <div class="actions-toolbar">
  208. <div class="primary">
  209. <button type="submit" class="action submit primary" title="<?= $block->escapeHtmlAttr(__('Create an Account')) ?>"><span><?= $block->escapeHtml(__('Create an Account')) ?></span></button>
  210. </div>
  211. <div class="secondary">
  212. <a class="action back" href="<?= $block->escapeUrl($block->getBackUrl()) ?>"><span><?= $block->escapeHtml(__('Back')) ?></span></a>
  213. </div>
  214. </div>
  215. </form>
  216. <script>
  217. require([
  218. 'jquery',
  219. 'mage/mage'
  220. ], function($){
  221.  
  222. var dataForm = $('#form-validate');
  223. var ignore = <?= /* @noEscape */ $_dob->isEnabled() ? ''input[id$="full"]'' : 'null' ?>;
  224.  
  225. dataForm.mage('validation', {
  226. <?php if ($_dob->isEnabled()): ?>
  227. errorPlacement: function(error, element) {
  228. if (element.prop('id').search('full') !== -1) {
  229. var dobElement = $(element).parents('.customer-dob'),
  230. errorClass = error.prop('class');
  231. error.insertAfter(element.parent());
  232. dobElement.find('.validate-custom').addClass(errorClass)
  233. .after('<div class="' + errorClass + '"></div>');
  234. }
  235. else {
  236. error.insertAfter(element);
  237. }
  238. },
  239. ignore: ':hidden:not(' + ignore + ')'
  240. <?php else: ?>
  241. ignore: ignore ? ':hidden:not(' + ignore + ')' : ':hidden'
  242. <?php endif ?>
  243. }).find('input:text').attr('autocomplete', 'off');
  244.  
  245. });
  246. </script>
  247. <?php if ($block->getShowAddressFields()): ?>
  248. <script type="text/x-magento-init">
  249. {
  250. "#country": {
  251. "regionUpdater": {
  252. "optionalRegionAllowed": <?= /* @noEscape */ $block->getConfig('general/region/display_all') ? 'true' : 'false' ?>,
  253. "regionListId": "#region_id",
  254. "regionInputId": "#region",
  255. "postcodeId": "#zip",
  256. "form": "#form-validate",
  257. "regionJson": <?= /* @noEscape */ $this->helper(MagentoDirectoryHelperData::class)->getRegionJson() ?>,
  258. "defaultRegion": "<?= (int) $block->getFormData()->getRegionId() ?>",
  259. "countriesWithOptionalZip": <?= /* @noEscape */ $this->helper(MagentoDirectoryHelperData::class)->getCountriesWithOptionalZip(true) ?>
  260. }
  261. }
  262. }
  263. </script>
  264. <?php endif; ?>
  265.  
  266. <script type="text/x-magento-init">
  267. {
  268. ".field.password": {
  269. "passwordStrengthIndicator": {
  270. "formSelector": "form.form-create-account"
  271. }
  272. }
  273. }
  274. </script>
  275.  
  276. /public_html/app/code/SAGOext/sago_cgrpd/etc/frontend/events.xml
  277.  
  278. <?xml version="1.0"?>
  279. <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
  280. <event name="customer_save_after">
  281. <observer name="setgroup" instance="SAGOsago_cgrpdObserverSetGroup" />
  282. </event>
  283. </config>
  284.  
  285. <?php
  286.  
  287. namespace SAGOextsago_cgrpdObserver;
  288.  
  289. use MagentoFrameworkEventObserverInterface;
  290.  
  291. class SetGroup implements ObserverInterface
  292. {
  293.  
  294.  
  295. private $customerRepository;
  296.  
  297. public function __construct(
  298. MagentoFrameworkAppRequestInterface $request,
  299. CustomerRepositoryInterface $customerRepository
  300. )
  301. {
  302. $this->_request = $request;
  303. $this->customerRepository = $customerRepository;
  304. }
  305. //ends here
  306. public function execute(
  307. MagentoFrameworkEventObserver $observer
  308. ){
  309.  
  310. $id = $observer->getEvent()->getCustomer()->getId();
  311. $customer = $this->customerRepository->getById($id);
  312.  
  313. $group_id = $this->_request->getParam('group_id');
  314.  
  315. $customer->setGroupId($group_id);
  316.  
  317. $this->customerRepository->save($customer);
  318.  
  319. }
  320. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement