For street address,you need do some coding.
At checkout, the fields are rendered from Magento\Checkout\Block\Checkout\AttributeMerger.
As for showing placeholder for street , go to the function getMultilineFieldConfig
, and paste:
if($attributeCode=='street') {
$line['label'] = $attributeConfig['label'];
}
After
if ($isFirstLine && isset($attributeConfig['default']) && $attributeConfig['default'] != null) {
$line['value'] = $attributeConfig['default'];
}
And see that magic. I have already tried it with a magento 2 instance, and it is working.
In Magento 2 you have to create custom JavaScript component responsible for redirect to a Payment Provider. So how it works in Magento 2.
Custom redirect.html template with "Place Order" button should be created
This template is controlled by a redirect.js JavaScript component with afterPlaceOrder
function inside which you can send HTTP GET request to your custom controller which will return parameters required for sending HTTP POST request to a payment gateway.
afterPlaceOrder: function () {
var self = this;
$.get(config.getDataUrl())
.done(function (response) {
customerData.invalidate(['cart']);
formBuilder(response).submit();
}).fail(function (response) {
errorProcessor.process(response, self.messageContainer);
}).always(function () {
fullScreenLoader.stopLoader();
});
}
The config.getDataUrl()
is custom controller URL. Here you do implement 2 different ways of POST parameters preparation. URL can be prepared from backend side and provided to a frontend by implementing the \Magento\Checkout\Model\ConfigProviderInterface::getConfig()
method.
Return key => value array of parameters as a response. The formBuilder(response).submit()
will foreach parameters and prepare form which will be submitted to a payment provider as post.
var formTmpl =
'<form action="<%= data.action %>" method="POST" hidden enctype="application/x-www-form-urlencoded">' +
'<% _.each(data.fields, function(val, key){ %>' +
'<input value="<%= val %>" name="<%= key %>" type="hidden">' +
'<% }); %>' +
'</form>';
return function (response) {
var inputs = {};
for (var index in response.fields) {
inputs[response.fields[index]] = response.values[index]
}
var hiddenFormTmpl = mageTemplate(formTmpl);
var tmpl = hiddenFormTmpl({
data: {
action: response.action,
fields: inputs
}
});
return $(tmpl).appendTo($('[data-container="body"]'));
};
Render form wrapped in a <html><body><form/></body></html>
on backend side using Block and *.phtml
file with inline JavaScript inside the response. Once retrieved, JavaScript will trigger redirect. It is less recommended way but might be less time consuming.
Best Answer
You start by defining a route for your module. This is done in
<module_directory>/etc/frontend/routes.xml
Then make the 'Index' controller for this route under
<module_directory>/Controller/Index.php
Make the layout file for this page under
<module_directory>/view/frontend/layout/timestwo_index.xml
Now make the template
<module_directory>/view/frontend/templates/form.phtml
Now make the controller for the result page:
<module_directory>/Controller/Result.php
Finally, make the layout xml for the result page in
<module_directory>/view/frontend/layout/timestwo_result.xml
Run
php bin/magento setup:upgrade
to enable your module, if you haven't already. Now clear the cache. Go to<magento_location>/timestwo
in browser to see the form.