Edit length of increment_id in sales_order table on Magento 2 - magento2

I want to decrease length of order increment #00000000001 to #00001.
I found some tutorials for magento 1 but not for Magento 2.
Please help if someone is aware how to perform this task.
Thanks

In the etc directory of your module, add a di.xml file with this content:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\SalesSequence\Model\Sequence">
<arguments>
<argument name="pattern" xsi:type="string"><![CDATA[%s%'.05d%s]]></argument>
</arguments>
</type>
</config>
This way Magento will pass a 5 digit pattern instead of its default pattern made by 9 digits.
This is because the first and the last %s symbol are replaced respectively with the prefix and the suffix values stored in the sales_sequence_profile table. The matching is done with the meta_id of your store (you can check yours by reading from the sales_sequence_meta table). The %'.05d pattern means that you want an integer with 5 padding digits on its left which is replaced with the next order number calculated by Magento.
For example, assuming that you have:
Prefix: PX
Suffix: SX
with the above pattern, the first order number will be PX00001SX

you can decrease length of order increment #00000000001 to #00001.
Try this: https://store.emizentech.com/magento2/custom-order-and-invoice-number-magento-2-0.html

Solved with a custom developed plugin:
I already had an observer to save the customer as new customer automatically after placing an order and before rendering the success page:
On the events.xml (already existing observer i've previously made)
<event name="sales_order_place_after">
<observer name="customcheckout_customer" instance="Dufry\CustomCheckout\Model\Observer\SaveCustomer"/>
</event>
On the observer SaveCustomer.php (already existing observer i've previously made):
$order = $observer->getOrder();
$increment = $order->getIncrementId();
if(strlen($increment) > 9){
$newIncrement = substr($increment, -8);
$newIncrement = substr($increment,0,1).$newIncrement;
$order->setIncrementId($newIncrement);
}
...
$order->save()
And worked like a charm.
I did the second "substr" part to keep the prefix the was previously configured.

Related

Checkout page shipping Address form edit Magento2

I need help for Magento 2.x shipping Address fields.
I want to change the Address label text using my new Label text.
Is there anyone you who have changed the Address Label text by own Lable Text. Could anyone please give the file path and where I can change the text for Checkout page Shipping address fields.
Please Take a look my screenshot below.
Here is the path where you can edit Address label text:
app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml
Following will be helpful
step 1 :
If you want to change the shipping address fields as well as billing address fields, You can do via theme transaction if you have made a custom theme as per your language.
i.e: en_US
Step 2 :
If you change made in shipping address fields only, Please override LayoutProcessor.php
step 2.1
di.xml
path: app/code/vendor/module_name/etc
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Checkout\Block\Checkout\LayoutProcessor">
<plugin name="Custom_Checkout" type="vendor\module_name\Block\LayoutProcessor" sortOrder="100"/>
</type>
</config>
Step 2:
LayoutProcessor.php
path:app/code/vendor/module_name/Block/
public function afterProcess(
\Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
array $jsLayout
) {
$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
['children']['shippingAddress']['children']['shipping-address-fieldset']['children']['lastname']['label'] = __('Recipient lastname');
$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
['children']['shippingAddress']['children']['shipping-address-fieldset']['children']['region_id']['label'] = __('Division');
return $jsLayout;
}
}
It's work like charm

Setting a default list of items in project_attribute in a GNAT GPS Plugin

I'm working on a custom GNAT GPS plugin (for GPS 6.1.2).
My plugin XML creates a project attribute "example_list_of_files".
This is a list of strings, that correspond the names of Ada files in the project.
I want to default the entries in that list to "a.adb","b.adb","c.adb". However I've been unable to find the correct syntax for this. Instead i end up with a single string of all the values.
What i want to see is what happens when you manually add three elements, as shown below:
Here is the code for this example:
GPS.parse_xml('<?xml version="1.0" ?>' + """
<my_plugin>
<project_attribute
name="example_list_of_files"
label="example_list_of_files"
description="A description...."
package="MyPackage"
editor_page="MyPage"
editor_section="Build"
hide_in="wizard library_wizard"
omit_if_default="false"
list="true"
base_name_only="true">
<string type="file" filter="project" default="'a.adb','b.adb','c.adb' " />
</project_attribute>
</my_plugin>""");
Notice the string element with the project attribute default. Instead of a list of entries in the project manager it gives me a single entry, containing the string "'a.adb', 'b.adb', 'c.adb'".
Anyone got any ideas? I've also tried multiple string elements, adding brackets, braces, square-brackets, space separators, prefixing with 'array(' with no luck.
thanks
Matt
It seems indeed this is not supported. The standard plug-in projects.py has several list attributes, but all of them have a single value as the default. I'll check what can be done to improve here.
However, your approach might be wrong in the first place. The default you are setting only concerns the project editor. That means that if a user uses a default project (like project default is end default) and never goes through the project editor, your attribute example_list_of_files will in fact not exist (and have a default empty value). So it seems that this should in fact be handled in your plug-in, when you query the value of the attribute (like via GPS.Project.get_attribute_as_list). If that function returns an empty list, then use ("a.adb", "b.adb", "c.adb") instead. That way, things work fine even with a default, unedited project.
From the GPS User's Guide:
The tag accepts the following attributes:
[...]
list (boolean, default false)
If true, the project attribute contains a list of values, as opposed
to a single value. An example is the list of source directories in
standard projects.
In your example:
<string type="file" filter="project" default="'a.adb','b.adb','c.adb' " />
This is a single string value. Instead, you should specify a list of string values, like this:
<string type="file" filter="project" default="a.adb" />
<string type="file" filter="project" default="b.adb" />
<string type="file" filter="project" default="c.adb" />

Creating a working copy for Plone 4 custom content types

I have created a custom Plone content type in my package i.e. my.product.
I am in need of integrating a working copy support: so that a "published" document (in my case, a published content type) stays online while it is being edited. Basically, I want to take advantage of 'Working Copy Support (Iterate)' provided by plone.app.iterate to achieve what is explained here. This will provide me with ability to check-in/check-out my changes.
Is this possible in Plone 4 with custom content types using Archetypes? How would one go about it if yes?
I added the following two files inside my.product/my/product/profiles/default folder and it appears to work:
diff_tool.xml
<?xml version="1.0"?>
<object>
<difftypes>
<type portal_type="MyCustomType">
<field name="any" difftype="Compound Diff for AT types"/>
</type>
</difftypes>
</object>
repositorytool.xml
<?xml version="1.0"?>
<repositorytool>
<policymap>
<type name="MyCustomType">
<policy name="at_edit_autoversion"/>
<policy name="version_on_revert"/>
</type>
</policymap>
</repositorytool>
I have never used plone.app.iterate, but this is the generic approach how to solve the problem.
Actions are installed by plone.app.iterate GenericSetup profile. You can see actions here:
https://github.com/plone/plone.app.iterate/blob/master/plone/app/iterate/profiles/default/actions.xml
Pay note to the line *available_expr* which tells when to show the action or not. It points to helper view with the conditition.
The view is defined here
https://github.com/plone/plone.app.iterate/blob/master/plone/app/iterate/browser/configure.zcml#L7
The checks that are performed for the content item if it's archiveable
https://github.com/plone/plone.app.iterate/blob/master/plone/app/iterate/browser/control.py#L47
Most likely the failure comes from if not interfaces.IIterateAware.providedBy condition. Your custom contennt must declare this interface. However, you can confirm this putting a pdb breakpoint in checkin_allowed(self) and step it though line-by-line and see what happens with your content type.

NLog Event Log Target: problems with Source/Provider Name & message format

I'm trying to use NLog to log events for a new application to a file and to the Event Log. I'm almost there, but not quite - I can get events logged to the Event Log, and in the Details/XML view (of the Event Log) everything looks OK. But in the General tab of the viewer, I don't get the event message displayed as expected; instead I get "DRGImporterError"; this matches which happens to be the SymbolicName (see below) from my EventLogMessages.mc file, but when I modified this value and recompiled the error message file, this didn't change. The event log source is 'DRGImporter' as is the application name, so I can't be sure what 'DRGImporterError' actually refers to!
I've manually created and edited the registry entries storing the EventMessageFile location: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\MyAppLog\DRGImporter. Originally, I pointed this key to my custom EventLogMessages.dll, but in trying to debug it, I also set it to one of the standard DLLs under \Windows\Microsoft.NET\..., but it didn't change the outcome.
I have a number of other applications using the same event log, but these use a different logging framework. Nevertheless they work, but more curiously, if I change the source that NLog points to to one of these older ones, NLog entries are logged successfully and the General view in the event log shows the expected text. The only difference I can see from the XML view is the EventRecordID and the timestamp, which is to be expected.
Is there another element to this equation that I am missing?
EventLogMessages.mc:
;//***********Event Definitions**************
MessageId=2000
SymbolicName=MailerError
Language=English
%1.
.
MessageId=2100
SymbolicName=DRGImporterError
Language=English
%1.
.
NLog.config:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true" autoReload="true" internalLogFile="nlog.log" internalLogLevel="Debug">
<targets>
<target name="eventLogHeaderTarget" xsi:type="EventLog" log="Hexadex" source="DRGImporter" eventId="0" layout="${message}" />
</targets>
<rules>
<logger name="appLogHeader" minlevel="Debug" writeTo="eventLogHeaderTarget" />
</rules>

How would you arrange an XML file for an Event/Item which occurs on a range of multiple Dates?

For instance, I have a movie/item. It opens on Jan 1 2010 and finishes on Jan 10 2010. Do I create an entry for each date that the movie/item occurs, repeating all the data for each date? or do I create two nodes within the movie/item specifying a start date and end date and create an argument to provide all the data as needed?
I want to be able to filter entries based on the movie/item Category eliminating repeats and also be able to sort the list by Date.
I hop I got you right. You'll see.
Why not separate like this:
<db>
<movies>
<movie id="in_ba">
<name>Inglorious Basterds</name>
<!-- more info here -->
</movie>
</movies>
<times>
<item movieid="in_ba">
<open>00.00.00 00:00:00.00 UTC+0</open>
<close>00.00.00 00:00:00.00 UTC+0</close>
</item>
</times>
</db>