When fake orders become a recurring problem Does someone keep placing fake orders in your Magento 2 store, perhaps using different email addresses or customer accounts each time? Apart from the unnecessary work involved, such orders can interfere with your…
Reading a customer attribute (Magento 2)
Want to read a particular customer attribute in Magento 2? Use the following code to retrieve an attribute value for any customer by customer ID:
|
1 2 3 4 5 6 7 8 9 10 11 12 |
public function __construct( \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository, ... ) { $this->customerRepository = $customerRepository; } $customer = $this->customerRepository->getById($customerId); $customAttr = $customer->getCustomAttribute('what_ever'); if ($customAttr) { echo $customAttr->getValue(); } |
Excluding the login page from Google’s index (Magento 2)
By default, the login page /customer/account/login/referer/aHR0cHM6Ly93d3cuc2FuaWRvZS5kZS9jdXN0b21lci9hY2NvdW50L2luZGV4Lw~~/ may be indexed by search engines such as Google. To prevent this, create or override the file customer_account_login.xml in your theme and add the following code:
|
1 2 3 4 5 6 |
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <head> <meta name="robots" content="noindex,nofollow" /> </head> </page> |
Redeploy the content, clear the cache and…
Customer grid does not show all customers (Magento 2)
If the customer grid in your Magento 2 admin area shows only some customers or none at all, run the following two commands from your Magento 2 root directory:
|
1 2 |
php bin/magento indexer:reset customer_grid php bin/magento indexer:reindex customer_grid |
Resetting a customer password using SQL (Magento 2)
Use the following SQL code to reset a customer’s password directly in your Magento 2 database.
|
1 2 3 4 5 |
SET @passwd='123456789', @salt=MD5(RAND()); UPDATE customer_entity SET password_hash = CONCAT(SHA2(CONCAT(@salt, @passwd), 256), ':', @salt, ':1') WHERE email = 'test@example.com'; |
Show address data (like company, name) on registration form (Magento 2)
By default, the Magento 2 registration form does not show address data such as the company, name or street. To change that, simply create customer_account_create.xml in the folder app/design/Your Vendor/Your Theme/Magento_Customer/layout and add the following code:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?xml version="1.0"?> <!-- /** * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ --> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="customer_form_register"> <arguments> <argument name="show_address_fields" xsi:type="string">1</argument> </arguments> </referenceBlock> </body> </page> |
Now just clear…
Showing address fields during registration (Magento 2)
To request address details during registration, create the file customer_account_create.xml im Verzeichnis app/design/YourVendor/YourTheme/Magento_Customer/layout and insert the following content:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?xml version="1.0"?> <!-- /** * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ --> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="customer_form_register"> <arguments> <argument name="show_address_fields" xsi:type="string">1</argument> </arguments> </referenceBlock> </body> </page> |
Clear the cache afterwards. Address fields should then appear when registering a new account.
Reading recurring profile data (Magento 1)
Magento stores the recurring profile directly on the customer object. You can read its data using the following code: $collection = Mage::getResourceModel(‘sales/recurring_profile_collection’)->addFieldToFilter(‘customer_id’, $customerId); $profileData = $collection->getData(); $profileData = Mage::getModel(‘sales/recurring_profile’)->load($profileData[0]['profile_id']); $profileShippingAddress = $profileData->getShippingAddressInfo(); // …
User not able to login after version update (Magento 1)
If the user is not able to login after a Magento version update, you have most likely overwritten the login.phtml template in your local theme. To fix that problem, open \customer\form\login.phtml in your local theme and add the following code…
Users cannot log in after a version update (Magento 1)
If a customer cannot log in after a Magento version update, you may have overridden login.phtml in your theme. Open \customer\form\login.phtml in your theme and insert the following code immediately after the form tags.
|
1 |
<?php echo $this->getBlockHtml('formkey'); ?> |