Advertisement
Guest User

Untitled

a guest
Nov 27th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.09 KB | None | 0 0
  1. <?php
  2. namespace <vendor_name><module>Setup;
  3.  
  4. use MagentoFrameworkModuleSetupMigration;
  5. use MagentoFrameworkSetupInstallDataInterface;
  6. use MagentoFrameworkSetupModuleContextInterface;
  7. use MagentoFrameworkSetupModuleDataSetupInterface;
  8.  
  9. /**
  10. * @codeCoverageIgnore
  11. */
  12. class InstallData implements InstallDataInterface
  13. {
  14. /**
  15. * Customer setup factory
  16. *
  17. * @var MagentoCustomerSetupCustomerSetupFactory
  18. */
  19. private $customerSetupFactory;
  20.  
  21. /**
  22. * Init
  23. *
  24. * @param MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory
  25. */
  26. public function __construct(MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory)
  27. {
  28. $this->customerSetupFactory = $customerSetupFactory;
  29. }
  30.  
  31. /**
  32. * {@inheritdoc}
  33. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  34. */
  35. public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
  36. {
  37. /** @var CustomerSetup $customerSetup */
  38. $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
  39.  
  40. $setup->startSetup();
  41.  
  42. $customerSetup->addAttribute(MagentoCustomerModelCustomer::ENTITY, 'profile_name', [
  43. 'type' => 'text',
  44. 'label' => 'Profile Name',
  45. 'input' => 'text',
  46. 'required' => 0,
  47. 'sort_order' => 110,
  48. 'visible' => 1,
  49. 'system' => 0,
  50. 'position' => 110
  51. ]);
  52. //add attribute to attribute set
  53. $attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'profile_name');
  54. $attribute->setData('used_in_forms', ['adminhtml_customer', 'customer_account_create', 'customer_account_edit']);
  55. $attribute->save();
  56.  
  57. $setup->endSetup();
  58. }
  59. }
  60.  
  61. <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
  62. <body>
  63. <referenceBlock name="customer_form_register">
  64. <action method="setTemplate">
  65. <argument name="template" xsi:type="string"><Vendor>_<module>::form/register.phtml</argument>
  66. </action>
  67. </referenceBlock>
  68. </body>
  69. </page>
  70.  
  71. <?php $_helper = $this->helper('<vendor><module>HelperData'); ?>
  72. <?php echo $block->getChildHtml('form_fields_before')?>
  73. <?php /* Extensions placeholder */ ?>
  74. <?php echo $block->getChildHtml('customer.form.register.extra')?>
  75. <form class="form create account form-create-account" action="<?php /* @escapeNotVerified */ echo $block->getPostActionUrl() ?>" method="post" id="form-validate" enctype="multipart/form-data" autocomplete="off">
  76. <fieldset class="fieldset create info">
  77. <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Personal Information') ?></span></legend><br>
  78. <input type="hidden" name="success_url" value="<?php /* @escapeNotVerified */ echo $block->getSuccessUrl() ?>">
  79. <input type="hidden" name="error_url" value="<?php /* @escapeNotVerified */ echo $block->getErrorUrl() ?>">
  80. <?php echo $block->getLayout()->createBlock('MagentoCustomerBlockWidgetName')->setObject($block->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?>
  81. <?php if ($block->isNewsletterEnabled()): ?>
  82. <div class="field choice newsletter">
  83. <input type="checkbox" name="is_subscribed" title="<?php /* @escapeNotVerified */ echo __('Sign Up for Newsletter') ?>" value="1" id="is_subscribed"<?php if ($block->getFormData()->getIsSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox">
  84. <label for="is_subscribed" class="label"><span><?php /* @escapeNotVerified */ echo __('Sign Up for Newsletter') ?></span></label>
  85. </div>
  86. <?php /* Extensions placeholder */ ?>
  87. <?php echo $block->getChildHtml('customer.form.register.newsletter')?>
  88. <?php endif ?>
  89.  
  90. <?php $_dob = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetDob') ?>
  91. <?php if ($_dob->isEnabled()): ?>
  92. <?php echo $_dob->setDate($block->getFormData()->getDob())->toHtml() ?>
  93. <?php endif ?>
  94.  
  95. <?php $_taxvat = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetTaxvat') ?>
  96. <?php if ($_taxvat->isEnabled()): ?>
  97. <?php echo $_taxvat->setTaxvat($block->getFormData()->getTaxvat())->toHtml() ?>
  98. <?php endif ?>
  99.  
  100. <?php $_gender = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetGender') ?>
  101. <?php if ($_gender->isEnabled()): ?>
  102. <?php echo $_gender->setGender($block->getFormData()->getGender())->toHtml() ?>
  103. <?php endif ?>
  104.  
  105. <!-- Custom code for Profile-Name Field -->
  106. <div class="field profile-name">
  107. <label for="profile-name" class="label"><span><?php /* @escapeNotVerified */ echo __('Profile Name') ?></span></label>
  108. <div class="control">
  109. <input type="text" name="profile_name" id="profile-name" value="<?php echo $block->escapeHtml($block->getFormData()->getData('profile_name')) ?>" title="<?php /* @escapeNotVerified */ echo __('Profile Name') ?>" class="input-text" maxlength="250">
  110. </div>
  111. </div>
  112. <!-- End -->
  113.  
  114. </fieldset>
  115. <?php if ($block->getShowAddressFields()): ?>
  116. <fieldset class="fieldset address">
  117. <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Address Information') ?></span></legend><br>
  118. <input type="hidden" name="create_address" value="1" />
  119. <div class="field company">
  120. <label for="company" class="label"><span><?php /* @escapeNotVerified */ echo __('Company') ?></span></label>
  121. <div class="control">
  122. <input type="text" name="company" id="company" value="<?php echo $block->escapeHtml($block->getFormData()->getCompany()) ?>" title="<?php /* @escapeNotVerified */ echo __('Company') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('company') ?>">
  123. </div>
  124. </div>
  125. <div class="field telephone">
  126. <label for="telephone" class="label"><span><?php /* @escapeNotVerified */ echo __('Phone Number') ?></span></label>
  127. <div class="control">
  128. <input type="text" name="telephone" id="telephone" value="<?php echo $block->escapeHtml($block->getFormData()->getTelephone()) ?>" title="<?php /* @escapeNotVerified */ echo __('Phone Number') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('telephone') ?>">
  129. </div>
  130. </div>
  131.  
  132. <?php $_streetValidationClass = $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('street'); ?>
  133.  
  134. <div class="field street required">
  135. <label for="street_1" class="label"><span><?php /* @escapeNotVerified */ echo __('Street Address') ?></span></label>
  136. <div class="control">
  137. <input type="text" name="street[]" value="<?php echo $block->escapeHtml($block->getFormData()->getStreet(0)) ?>" title="<?php /* @escapeNotVerified */ echo __('Street Address') ?>" id="street_1" class="input-text <?php /* @escapeNotVerified */ echo $_streetValidationClass ?>">
  138. <div class="nested">
  139. <?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
  140. <?php for ($_i = 2, $_n = $this->helper('MagentoCustomerHelperAddress')->getStreetLines(); $_i <= $_n; $_i++): ?>
  141. <div class="field additional">
  142. <label class="label" for="street_<?php /* @escapeNotVerified */ echo $_i ?>">
  143. <span><?php /* @escapeNotVerified */ echo __('Address') ?></span>
  144. </label>
  145. <div class="control">
  146. <input type="text" name="street[]" value="<?php echo $block->escapeHtml($block->getFormData()->getStreetLine($_i - 1)) ?>" title="<?php /* @escapeNotVerified */ echo __('Street Address %1', $_i) ?>" id="street_<?php /* @escapeNotVerified */ echo $_i ?>" class="input-text <?php /* @escapeNotVerified */ echo $_streetValidationClass ?>">
  147. </div>
  148. </div>
  149. <?php endfor; ?>
  150. </div>
  151. </div>
  152. </div>
  153.  
  154. <div class="field required">
  155. <label for="city" class="label"><span><?php /* @escapeNotVerified */ echo __('City') ?></span></label>
  156. <div class="control">
  157. <input type="text" name="city" value="<?php echo $block->escapeHtml($block->getFormData()->getCity()) ?>" title="<?php /* @escapeNotVerified */ echo __('City') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('city') ?>" id="city">
  158. </div>
  159. </div>
  160.  
  161. <div class="field region required">
  162. <label for="region_id" class="label"><span><?php /* @escapeNotVerified */ echo __('State/Province') ?></span></label>
  163. <div class="control">
  164. <select id="region_id" name="region_id" title="<?php /* @escapeNotVerified */ echo __('State/Province') ?>" class="validate-select" style="display:none;">
  165. <option value=""><?php /* @escapeNotVerified */ echo __('Please select a region, state or province.') ?></option>
  166. </select>
  167. <input type="text" id="region" name="region" value="<?php echo $block->escapeHtml($block->getRegion()) ?>" title="<?php /* @escapeNotVerified */ echo __('State/Province') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('region') ?>" style="display:none;">
  168. </div>
  169. </div>
  170.  
  171. <div class="field zip required">
  172. <label for="zip" class="label"><span><?php /* @escapeNotVerified */ echo __('Zip/Postal Code') ?></span></label>
  173. <div class="control">
  174. <input type="text" name="postcode" value="<?php echo $block->escapeHtml($block->getFormData()->getPostcode()) ?>" title="<?php /* @escapeNotVerified */ echo __('Zip/Postal Code') ?>" id="zip" class="input-text validate-zip-international <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('postcode') ?>">
  175. </div>
  176. </div>
  177.  
  178. <div class="field country required">
  179. <label for="country" class="label"><span><?php /* @escapeNotVerified */ echo __('Country') ?></span></label>
  180. <div class="control">
  181. <?php echo $block->getCountryHtmlSelect() ?>
  182. </div>
  183. </div>
  184. <?php $addressAttributes = $block->getChildBlock('customer_form_address_user_attributes');?>
  185. <?php if ($addressAttributes): ?>
  186. <?php $addressAttributes->setEntityType('customer_address'); ?>
  187. <?php $addressAttributes->setFieldIdFormat('address:%1$s')->setFieldNameFormat('address[%1$s]');?>
  188. <?php $block->restoreSessionData($addressAttributes->getMetadataForm(), 'address');?>
  189. <?php echo $addressAttributes->setShowContainer(false)->toHtml()?>
  190. <?php endif;?>
  191. <input type="hidden" name="default_billing" value="1">
  192. <input type="hidden" name="default_shipping" value="1">
  193. </fieldset>
  194.  
  195. <?php endif; ?>
  196. <fieldset class="fieldset create account" data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>">
  197. <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Sign-in Information') ?></span></legend><br>
  198. <div class="field required">
  199. <label for="email_address" class="label"><span><?php /* @escapeNotVerified */ echo __('Email') ?></span></label>
  200. <div class="control">
  201. <input type="email" name="email" autocomplete="email" id="email_address" value="<?php echo $block->escapeHtml($block->getFormData()->getEmail()) ?>" title="<?php /* @escapeNotVerified */ echo __('Email') ?>" class="input-text" data-validate="{required:true, 'validate-email':true}">
  202. </div>
  203. </div>
  204. <div class="field password required" data-mage-init='{"passwordStrengthIndicator": {}}'>
  205. <label for="password" class="label"><span><?php /* @escapeNotVerified */ echo __('Password') ?></span></label>
  206. <div class="control">
  207. <input type="password" name="password" id="password"
  208. title="<?php /* @escapeNotVerified */ echo __('Password') ?>"
  209. class="input-text"
  210. data-password-min-length="<?php echo $block->escapeHtml($block->getMinimumPasswordLength()) ?>"
  211. data-password-min-character-sets="<?php echo $block->escapeHtml($block->getRequiredCharacterClassesNumber()) ?>"
  212. data-validate="{required:true, 'validate-customer-password':true}"
  213. autocomplete="off">
  214. <div id="password-strength-meter-container" data-role="password-strength-meter" >
  215. <div id="password-strength-meter" class="password-strength-meter">
  216. <?php /* @escapeNotVerified */ echo __('Password Strength'); ?>:
  217. <span id="password-strength-meter-label" data-role="password-strength-meter-label" >
  218. <?php /* @escapeNotVerified */ echo __('No Password'); ?>
  219. </span>
  220. </div>
  221. </div>
  222. </div>
  223.  
  224. </div>
  225. <div class="field confirmation required">
  226. <label for="password-confirmation" class="label"><span><?php /* @escapeNotVerified */ echo __('Confirm Password') ?></span></label>
  227. <div class="control">
  228. <input type="password" name="password_confirmation" title="<?php /* @escapeNotVerified */ echo __('Confirm Password') ?>" id="password-confirmation" class="input-text" data-validate="{required:true, equalTo:'#password'}" autocomplete="off">
  229. </div>
  230. </div>
  231. <?php echo $block->getChildHtml('form_additional_info'); ?>
  232. </fieldset>
  233. <div class="actions-toolbar">
  234. <div class="primary">
  235. <button type="submit" class="action submit primary" title="<?php /* @escapeNotVerified */ echo __('Create an Account') ?>"><span><?php /* @escapeNotVerified */ echo __('Create an Account') ?></span></button>
  236. </div>
  237. <div class="secondary">
  238. <a class="action back" href="<?php echo $block->escapeUrl($block->getBackUrl()) ?>"><span><?php /* @escapeNotVerified */ echo __('Back') ?></span></a>
  239. </div>
  240. </div>
  241. </form>
  242. <script>
  243. require([
  244. 'jquery',
  245. 'mage/mage'
  246. ], function($){
  247.  
  248. var dataForm = $('#form-validate');
  249. var ignore = <?php /* @escapeNotVerified */ echo $_dob->isEnabled() ? ''input[id$="full"]'' : 'null'; ?>;
  250.  
  251. dataForm.mage('validation', {
  252. <?php if ($_dob->isEnabled()): ?>
  253. errorPlacement: function(error, element) {
  254. if (element.prop('id').search('full') !== -1) {
  255. var dobElement = $(element).parents('.customer-dob'),
  256. errorClass = error.prop('class');
  257. error.insertAfter(element.parent());
  258. dobElement.find('.validate-custom').addClass(errorClass)
  259. .after('<div class="' + errorClass + '"></div>');
  260. }
  261. else {
  262. error.insertAfter(element);
  263. }
  264. },
  265. ignore: ':hidden:not(' + ignore + ')'
  266. <?php else: ?>
  267. ignore: ignore ? ':hidden:not(' + ignore + ')' : ':hidden'
  268. <?php endif ?>
  269. }).find('input:text').attr('autocomplete', 'off');
  270.  
  271. });
  272. </script>
  273. <?php if ($block->getShowAddressFields()): ?>
  274. <script type="text/x-magento-init">
  275. {
  276. "#country": {
  277. "regionUpdater": {
  278. "optionalRegionAllowed": <?php /* @escapeNotVerified */ echo($block->getConfig('general/region/display_all') ? 'true' : 'false'); ?>,
  279. "regionListId": "#region_id",
  280. "regionInputId": "#region",
  281. "postcodeId": "#zip",
  282. "form": "#form-validate",
  283. "regionJson": <?php /* @escapeNotVerified */ echo $this->helper('MagentoDirectoryHelperData')->getRegionJson() ?>,
  284. "defaultRegion": "<?php /* @escapeNotVerified */ echo $block->getFormData()->getRegionId() ?>",
  285. "countriesWithOptionalZip": <?php /* @escapeNotVerified */ echo $this->helper('MagentoDirectoryHelperData')->getCountriesWithOptionalZip(true) ?>
  286. }
  287. }
  288. }
  289. </script>
  290. <?php endif; ?>
  291.  
  292. <?php
  293. MagentoFrameworkComponentComponentRegistrar::register(
  294. MagentoFrameworkComponentComponentRegistrar::MODULE,
  295. 'Vendor_Module',
  296. __DIR__
  297.  
  298. <?php
  299. namespace VendorModuleSetup;
  300. use MagentoFrameworkSetupInstallDataInterface;
  301. use MagentoFrameworkSetupModuleDataSetupInterface;
  302. use MagentoFrameworkSetupModuleContextInterface;
  303.  
  304. class InstallData implements InstallDataInterface {
  305.  
  306. private $_eavSetupFactory;
  307. private $_attributeRepository;
  308.  
  309. public function __construct(
  310. MagentoEavSetupEavSetupFactory $eavSetupFactory,
  311. MagentoEavModelAttributeRepository $attributeRepository
  312. )
  313. {
  314. $this->_eavSetupFactory = $eavSetupFactory;
  315. $this->_attributeRepository = $attributeRepository;
  316. }
  317.  
  318. public function install( ModuleDataSetupInterface $setup, ModuleContextInterface $context )
  319. {
  320.  
  321. $eavSetup = $this->_eavSetupFactory->create(['setup' => $setup]);
  322.  
  323. // add customer_mob to customer
  324. $eavSetup->removeAttribute(MagentoCustomerModelCustomer::ENTITY, 'customer_mobile');
  325. $eavSetup->addAttribute(
  326. MagentoCustomerModelCustomer::ENTITY, 'customer_mobile', [
  327. 'type' => 'varchar',
  328. 'label' => 'Customer Mobile',
  329. 'input' => 'text',
  330. 'required' => true,
  331. 'system' => 0,
  332. 'global' => MagentoEavModelEntityAttributeScopedAttributeInterface::SCOPE_STORE,
  333. 'sort_order' => 75,
  334. 'is_used_in_grid' => 1,
  335. 'is_visible_in_grid' => 1,
  336. 'unique' => true,
  337. ]
  338. );
  339.  
  340. // allow customer_mob attribute to be saved in the specific areas
  341. $attribute = $this->_attributeRepository->get('customer', 'customer_mobile');
  342. $setup->getConnection()
  343. ->insertOnDuplicate(
  344. $setup->getTable('customer_form_attribute'),
  345. [
  346. ['form_code' => 'adminhtml_customer', 'attribute_id' => $attribute->getId()],
  347. ['form_code' => 'customer_account_create', 'attribute_id' => $attribute->getId()],
  348. ['form_code' => 'customer_account_edit', 'attribute_id' => $attribute->getId()],
  349. ]
  350. );
  351. }
  352.  
  353. <?xml version="1.0" encoding="UTF-8"?>
  354. <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
  355. <module name="Vendor_Module" setup_version="1.0.0">
  356. <sequence>
  357. <module name="Magento_Customer"/>
  358. </sequence>
  359. </module>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement