Extends Shopware Models - shopware

I need to extend Shopware variants models in order to add some custom attributes such as the type of metal,the type of stone a jewel, which is the base article.
These attributes will be used both in backend and frontend.
How can I do that? Thanks

Extending the Shopware core model itself is not possible at all. Depending on what specific model you are trying to extend there would be two different ways for some workaround:
If its the article itself that you want to extend you could use the custom attribute fields as described here: http://community.shopware.com/Anlegen,-Anpassen-und-Ausgabe-von-Artikel-Attributen_detail_1208.html
Another way would be to write a plugin where you create attribute fields by code on plugin install(). This is only possible on entities that do have an attribute table which belongs to the entity itself. For example s_order and s_order_attributes
For the second way create a method in your plugin's Bootstrap.php like the following and call the method in the plugin's install() method:
public function installOrderAttributes()
{
Shopware()->Models()->addAttribute(
's_order_attributes',
'ordermod',
'Random1',
'DECIMAL(12,4)',
false,
0.0000);
Shopware()->Models()->addAttribute(
's_order_attributes',
'ordermod',
'Random2',
'DECIMAL(12,4)',
false,
0.0000);
$metaDataCacheDoctrine = Shopware()->Models()->getConfiguration()->getMetadataCacheImpl();
$metaDataCacheDoctrine->deleteAll();
Shopware()->Models()->generateAttributeModels(array('s_order_attributes'));
}
The addAttribute() function in /engine/Shopware/Components/Model/ModelManager.php has the following signature:
/**
* Shopware helper function to extend an attribute table.
*
* #param string $table Full table name. Example: "s_user_attributes"
* #param string $prefix Column prefix. The prefix and column parameter will be the column name. Example: "swag".
* #param string $column The column name
* #param string $type Full type declaration. Example: "VARCHAR( 5 )" / "DECIMAL( 10, 2 )"
* #param bool $nullable Allow null property
* #param null $default Default value of the column
* #throws \InvalidArgumentException
*/
public function addAttribute($table, $prefix, $column, $type, $nullable = true, $default = null);
Hope this will help.
Kind regards!

Related

Replace string with another string across few folders, leaving a variable in a replaced string intact

I have 3 unrelated java selenium repos which utilise extensively a following block of code to get text from list of elements:
getVisibleElements(someElement)
.stream()
.map(WebElement::getText)
.toList();
I have written a method in a base class that is extended by another classes, so I don't have to write such verbose code every time I want to extract text from elements:
/**
* Get text from multiple elements
*
* #param locator element
* #param T either {#code By} or {#code List<WebElement>}.
* #return List of elements' text
*/
protected final <T> List<String> getTexts(T locator) {
return getVisibleElements(locator)
.stream()
.map(WebElement::getText)
.toList();
}
if anyone wanted to know this is getVisibleElements(T locator) implementation, but it's a bit offtopic:
#SuppressWarnings("unchecked")
protected final <T> List<WebElement> getVisibleElements(T locator) {
return wait.until(isBy(locator)
? ExpectedConditions.visibilityOfAllElementsLocatedBy((By) locator)
: ExpectedConditions.visibilityOfAllElements((List<WebElement>) locator));
}
where wait is an instance of WebDriverWait.
Now, I would like to write some script (I was thinking Python or Perl), which would take folders, where these repos are, as input and simply replace all these code blocks with my new short method, leaving only method argument intact, so, for example:
List<String> tileTexts = getVisibleElements(attachmentFileNameDiv)
.stream()
.map(WebElement::getText)
.toList();
becomes:
List<String> tileTexts = getTexts(attachmentFileNameDiv);
I could of course use IDE replace feature and go thru all the files, however I would like to do it in a more efficient way. I have unfortunately no knowlegde of scripting and if someone helped me to write such script, or showed perhaps some tool that could help with string processing I could use this knowledge and use it to further refacor my repos.

How to get the class name inside a child window using pywinauto?

I am trying to automate an app using pywinauto. Here is a problem when I need to locate a specific window.
For example, I want to get the window 'AfxWnd4214', but I can only access to window "AfxWnd42".
| AfxWnd42 - '' (L1044, T410, R1060, B426)
| ['AfxWnd4214', 'V11.82AfxWnd4212']
| child_window(class_name="AfxWnd42")
| AfxWnd42 - '' (L1044, T410, R1060, B426)
| ['AfxWnd4212', 'V11.82AfxWnd4212']
| child_window(class_name="AfxWnd42")
I access it by this code. But it is not specific enough. The sequence of this window may change in the tree.
pywinauto.app.window(class_name = "AfxWnd42", found_index = 0)
When I try this code:
pywinauto.app.window(class_name = "AfxWnd4214", found_index = 0)
It says
pywinauto.findwindows.ElementNotFoundError: {'class_name': 'AfxWnd4214', 'found_index': 0, 'backend': 'win32', 'process': 15404}
Is there any better method to access this window?
Thank you.
There are various search criteria see below; Try using combination of these.
Once I used auto_id and it worked for me.
'''
Find elements based on criteria passed in
Possible values are:
* **class_name** Elements with this window class
* **class_name_re** Elements whose class matches this regular expression
* **parent** Elements that are children of this
* **process** Elements running in this process
* **title** Elements with this text
* **title_re** Elements whose text matches this regular expression
* **top_level_only** Top level elements only (default=True)
* **visible_only** Visible elements only (default=True)
* **enabled_only** Enabled elements only (default=False)
* **best_match** Elements with a title similar to this
* **handle** The handle of the element to return
* **ctrl_index** The index of the child element to return
* **found_index** The index of the filtered out child element to return
* **predicate_func** A user provided hook for a custom element validation
* **active_only** Active elements only (default=False)
* **control_id** Elements with this control id
* **control_type** Elements with this control type (string; for UIAutomation elements)
* **auto_id** Elements with this automation id (for UIAutomation elements)
* **framework_id** Elements with this framework id (for UIAutomation elements)
* **backend** Back-end name to use while searching (default=None means current active backend)
'''

Get actual record of applied record with SuiteScript 2.0

I want to be able to get the shipping/billing address from the applied records when doing something like a Customer Refund.
This is the data I see from an applied record:
amount = {string} 2.56
apply = {string} T
applydate = {string} 11/6/2018
createdfrom = {object} null
doc = {string} 792
due = {string} 2.56
duedate = {object} null
internalid = {string} 792
line = {string} 1
pymt = {object} null
refnum = {string} 63
sys_id = {string} 4917587510484347
sys_parentid = {string} 4917587510342093
total = {string} 2.56
trantype = {string} CustPymt
type = {string} Payment
I initially tried doing this by using the record.Load function. The issue is that this function requires passing in the record type, which isn't given clearly in the apply sublist. I initially tried using the type field, but as you can see above. The proper type is record.Type.CUSTOMER_PAYMENT and here the value just shows as Payment. I switched to using the trantype and having a mapping function, but I don't have all the possible mappings.
My questions are:
Is there an entirely better way of getting the shipping and billing information from the applied record
If the answer to 1 is no, is there a way to get the actual record type from the apply sublist?
If the answer to 2 is no, is there somewhere to have all possible mappings of trantype to record.Type?
You can do a lookup of the address values using search.Type.TRANSACTION like below:
var addressValues = search.lookupFields({
type: search.Type.TRANSACTION,
id: 792,
columns: ['shipaddress', 'billaddress']
});
Address in NetSuite is different record, linked here. So you have to use search, as described above.

How to get default value of the field in Netsuite using RESTlet?

I am getting all required fields (Standard & Custom) through the following RESTlet file function name getFields.
https://gist.githubusercontent.com/ganeshprabhus/68a9e5b81e53436bb1d684f857a6c31f/raw/67fe03895f1c31d65c1f283dd51584af45d27c59/NS_Script_2016.2004
I could get fields' type and label. i want to get the default value of the field.
Thanks in advance
You should be able to use:
field_details['Value'] = record.getFieldValue(fieldName);
field_details['Text'] = record.getFieldText(fieldName);
to pull the value and display text of those fields off the record object. Running that through on a customer record will give you results like this:
customform = {object}
Type = {string} select
Label = {string} Custom Form
Value = {number} 23
Text = {string} XX Customer Form

Groovydoc: Documenting named parameters

I've created a method like so:
void myMethod(Map kwArgs, def myParam)
{
println kwArgs.firstName
println [kwArgs.lastName, "Wilcox"].find()
// ^^^ if lastName named parameter not specified, "Wilcox"
....
}
Now comes the time to document this method with GroovyDoc. Part of it is easy
/**
myMethod rules the world
#param myParam something something
But how do I document the named parameters? (Likewise, how can I specify that the lastName parameter has a default? (ie is there some metadata I can set or just make that explicit to the reader in the English description?)
But how do I document the named parameters?
Unless you are considering writing a customer doclet or similar, I think you will just document them as text in the comment.

Resources