How to add custom field in Premium items Module in Shopware 5? - custom-fields

I am new in Shopware 5. I want to create custom field in Premium item module.
Please check the screenshot.
I have checked there is no any attribute table for Premium items.
Please tell me how I can create custom field here:

You did not mention what you tried so far, so I will give you some basic information how to start. Feel free to come back with more questions.
Adding the field endPrice to the detail view
The component you want to extend is Shopware.apps.Premium.view.premium.Detail.
You can add your new field, with similar code as the startPrice field.
See the developer guide on backend extensions. This will guide you trough the steps required to extend the detail window. (more information about detail windows is also available)
Extending JS Model / Controller
Basically I recommend to full text search through https://github.com/shopware/shopware/tree/5.7/themes/Backend/ExtJs/backend/premium for startPrice. This will give you a hint what else to extend, to be able to persist your new field endPrice.
Implementing the storage logic
You also need to implement the logic so that the setting actually will be saved. This core code is in Premium.php - there is a special formatting for start-price:
$params['startPrice'] = str_replace(',', '.', $params['startPrice']);
which you might do via a hook.
The basic parameters are stored in s_addon_premiums, but you cannot extend the core model, so you might want to use workarounds as described in another StackOverflow question to store the value of your new endPrice field.
Adding the logic
Finally you can hook into sGetPremiums. You can use an after hook to remove those premium items which should not be added from the returned $premiums array, because the order exceeds the endPrice.

Related

What kind of hook can I use if I want to change my custom price on Woocommerce bulk edit page?

I created custom price for WC_Product, put them into WC Bulk Edit Page and want to save changed values to disk.
I have seen class WC_Admin_Post_Types (woocommerce/includes/admin/class-wc-admin-post-types.php) and found there some kind of hooks.
I tried to hook `woocommerce_product_bulk_edit_save', but this trigger does not work (or I did something wrong there).
I did find examples in WWW, but then I shall create and use wp_ajax_{something} and 20-30 lines JS code.
May be exists another way for this - my custom price needs all the same as native WC price - where can I see how they are handled and save?
I was able to connect my custom function to hook `woocommerce_product_bulk_edit_save': this hook run if any of native Bulk Edit Fields will be filled, but I filled my custom field only. All should be fine. Thanks if you read this).

Response comments added to the wrong parent document

I have a view data source that uses a view key to access documents and show them in a repeat with var "posts". within the repeat I have a document data source with var "post" that gets's the the unid of the documents using posts.getUniversalID().
further down the repeat I have another document data source "newcomment" that is a response and take the parent id as: post.getDocument().getUniversalID()
below the newcomment data source I have an editbox and a submit button which saves the comment as a response to the "post" using newcomment.save()
Here is my problem
two people access the same xpage. personA enters the page and starts writing a comment to a post. in the same time personB creates a new post and submit it before personA submits the comment. What happens now is that the comments gets binded to the latest post and not to the post personA responded to.
I tried anothoher thing also, let's say there is 10 posts in that database. personA and personB access the xpages. personA start writing a comment to post number 8. at the same time personB creates two new posts in the database. when personA now submits the comment it seem to get bind to the same index which is now two posts up. but still index 8. which is ofcourse the wrong post.
If I change the repeat to "createControlsAtPageCreation" ie.e repeatControls=true the comment is attached to the correct post but then I run into another problem that the view is not updated to show the latest posts.
my repeat is wihtin a custom control that is loaded dynamically using the dynamic content control in extlib.
As information here is what I have found about the repeatControls settings
Setting the repeatControls property to true instructs the repeat control to create a new copy of its children for each iteration over the dataset.
When the Repeat control is configured with the property
repeatControls=“true” , it repeats its contents only once, at page load time
So my question here is that I do not understand what is going on. why is my comment attached to the wrong parent document? and is there a way I can prevent this and still have new posts displayed correctly
thanks for your help
Without the code it's a bit hard to imagine what exactly is going one here but this looks very similar to problem that I had with repeat control and value binding.
Long story short the problem was connecet to repeatControls property set to false. When it was like that data binding were working only for first element in collection - all data was somehow magically saved to this first object! I managed to get this working by using combination of dynamic content control rebuild and repeatControls set to true. Only then databindings were working property.
It seems like if You are repeating rendering only (and this is what repeatControls set to false do) the decoding phase of jsf lifecycle goes foobar.
Without your XSP markup, it's difficult to be absolutely definitive but it appears that you're app code is creating and persisting the datasources and components per row during page load - therefore increasing the overall size and complexity of the component tree also. You should alternatively try an approach that will lazy-load the datasource only when requested by the end-user (eg: edit / reply).
Refer to the XPages Extension Library demo application (XPagesExt.nsf) for examples that use such a dynamic approach. In particular, look at Core_InPlaceForm.xsp which demonstrates using the xe:inPlaceForm control within a xp:repeat. And also see Domino_ForumView.xsp which demonstrates using the xe:forumView and xe:forumPost controls to manage and visualize a hierarchical thread. Also consider the concurrency mode that best suits your requirements when it actually comes to saving any given post or comment (fail, createConflict, force, exception) and document locking for high contention situations. The above-mentioned controls all provide the highest level of dynamic control and datasource creation and destruction.
Please feel free to send me on a worked example database, where I can understand your exact use case - DM me or email me.

Auto Search functionality for Schools/Universities using Asp.Net MVC

I am building a website where the user should have the capability of adding their School/University. I have noticed in LinkedIn, when i tried to type in my school name , it showed up a auto search box with all the schools, beginning with the letter i typed. How can i achieve the same functionality?
Do they save all the Universities in their database ? Or is there any Open webservices i can use that will show all the Schools/Universities ?
Thanks !
This feature is called "Auto Complete" and the text boxes are enabled with that. These allow you to filter the data required according to the characters you type in.
Please see this post for auto-complete feature implemented using jQuery.
Razor: Auto-complete text box inside jqGrid, How to bind values?
The example shown in that page lists all from the database. However, as a next phase, you can as well extend this feature to look for a WCF exposed service for universe of schools/colleges.
FYI" "GetSkillNameAutocomplete" is a method in the controller that takes a string parameter as an input (the search string) and gets the value(s).
Hope this helps!

How to create a tagging system like on Stack Overflow or Quora

I want to create a tagging system like seen here on Stack Overflow or on Quora. It'll be its own model, and I'm planning on using this autocomplete plugin to help users find tags. I have a couple of questions:
I want tags to be entirely user-generated. If a user inputs a new tag by typing it and pressing an "Add" button, then that tag is added to the db, but if a user types in an existing tag, then it uses that one. I'm thinking of using code like this:
def create
#video.tags = find_or_create_by_name(#video.tags.name)
end
Am I on the right track?
I'd like to implement something like on Stack Overflow or Quora such that when you click a tag from the suggested list or click an "Add" button, that tag gets added right above the text field with ajax. How would I go about implementing something like that?
I know this is kind of an open-ended question. I'm not really looking for the exact code as much as a general nudge in the right direction. Of course, code examples wouldn't hurt :)
Note I am NOT asking for help on how to set up the jQuery autocomplete plugin... I know how to do that. Rather, it seems like I'll have to modify the code in the plugin so that instead of the tags being added inside the text field, they are added above the text field. I'd appreciate any direction with this.
mbleigh's acts_as_taggable_on gem is a feature-complete solution that you should definitely look into a little more closely. The implementation is rock-solid and flexible to use. However, it is mostly concerned with attaching tags to objects, retrieving tags on objects, and searching for tagged items. This is all backend server stuff.
Most of the functionality you are looking to change (based on your comments) is actually related more to your front-end UI implementation, and the gem doesn't really do much for you there. I'll take your requests one-by-one.
If user inputs a new tag, that tag
gets added, if user inputs an
existing tag, the existing tag gets
used. acts_as_taggable_on does this.
Click a tag from suggested list to
add that tag. This is an
implementation issue - on the
back-end you'll need to collect the
suggested list of tags, then display
those in your presentation as links
to your processing function.
Autocomplete as user enters
potential tag. You'll use the jQuery
autocomplete plugin against a list
of items pulled off the tags table.
With additional jQuery, you can
capture when they've selected one of
the options, or completed entering
their new tag, and then call the
processing function.
Restrict users to entering only one
tag. This will be your UI
implementation - once they've
entered or selected a tag, you
process it. If they enter two words
separated by a comma, then before or
during processing you have to either
treat it as one tag, or take only
the text up to the first comma and
discard the rest.
When you process the addition of a
tag, you will have to do two things.
First, you'll need to handle the UI
display changes to reflect that a
tag has been entered/chosen. This
includes placing the tag in the
"seleted" area, removing it from the
"available" display, updating any
counters, etc. Second, you'll need
to send a request to the server to
actually add the tag to the object
and persist that fact to the
database (where the taggable gem will take over for you). You can either do this via
an individual AJAX request per tag,
or you can handle it when you submit
the form. If the latter, you'll need
a var to keep the running list of
tags that have been added/removed
and you'll need code to handle
adding/removing values to that var.
For an example of saving tags while editing but not sending to server/db until saving a form, you might take a look at the tagging functionality on Tumblr's new post page. You can add/remove tags at will while creating the post, but none of it goes to the database until you click save.
As you can see, most of this is on you to determine and code, but has very little to do with the backend part. The gem will take care of that for you quite nicely.
I hope this helps get you moving in the right direction.
The more I try to force the acts-as-taggable-on gem to work the more I think these are fundamentally different types of problems. Specifically because of aliases. The gem considers each tag to be its own special snowflake, making it difficult to create synonyms. In some cases it doesn't go far enough, if you want the Tag to have a description you'd need to edit the given migrations (which isn't hard to do).
Here's what I'm considering implementing, given the trouble I've had implementing via the gem. Let's assume you want to create a tagging system for Technologies.
Consider the following psuedo code, I haven't yet tested it.
rails g model Tech usage_count::integer description:text icon_url:string etc. Run the migration. Note the
Now in the controller you will need to increment usage_count each time something happens, the user submits a new question tagged with given text.
rails g model Name::Tech belongs_to:Tech name:string
Name::Tech model
belongs_to :tech
end
Then you could search via something like:
search = Name::Tech.where("name LIKE :prefix", prefix: "word_start%")
.joins(:tech)
.order(usage_count: desc)
.limit(5)
This is starting point. It's fundamentally different from the gem, as each tag is just a string on its own, but references a richer data table on the back end. I'll work on implementing and come back to update with a better solution.

SharePoint - checking Content Approval change status in event receiver

I have a SharePoint list with Content Approval enabled. The business requirement is that once the new list item is approved it should stay approved despite further updates by any user.
My first thought was to handle the ItemUpdating method, and if the corresponding before property is Approved then set the after property to Approved. This doesn't work however.
In the ItemUpdating method the "Approval Status" column does not show up in properties.BeforeProperties or properties.AfterProperties. properties.ListItem["Approval Status"] and properties.ListItem.ModerationInformation.Status both show the "before" value. In the ItemUpdated method the situation is the same, except instead the values shown are the "after" values.
Is there a way in either method to identify both the before and after methods? I can work around this by creating a new hidden column that I set when the item is approved but that doesn't seem best.
Should I be approaching this from a workflow perspective?
Would this help?
http://www.synergyonline.com/blog/blog-moss/Lists/Posts/Post.aspx?ID=25
Use field's internal name with AfterProperties or BeforeProperties.
i.e. properties.AfterProperties["internal name"].
It works for me
Please refer to the following properties in the AfterProperties section for a document library.
Document libraries are a bit different than lists. the doc libraries have .AfterProperties["vti_doclibmodstat"] and .AfterProperties["vti_doclibmodcomm"].

Resources