nopCommerce 3.0 How to get user selected store and category on product detail page? - nopcommerce

I want to show user selected store and category on product detail page like this
Store Name Category Name > Product Name.
How can I get user selected store and category from Product detail page. I use nopCommerce 3.0.

For the store name, you can use the store context object:
_storeContext.CurrentStore
But for the category, are you aware that a product can belong to multiple categories in nopCommerce? This is stored in the ProductCategories collection of the Product entity.

I have a problem with
_storeContext.CurrentStore
This everytime gives me wrong store information and the reason is described here
plugin-get-current-storeid-multi-store
So i have used the below code which i got from looking NivoSlider Plugin .
var storeScope = this.GetActiveStoreScopeConfiguration(_storeService,
_workContext);
_storeService is type of IStoreService
_workContext is type of IWorkContext
Use it via dependency injection from constructor.

Related

Is it possible to pass a special query parameter value to a WooCommerce product link?

I am looking to use WooCommerce in a bit of a strange way, and I'm wondering if there is any way to make this possible. Here's my desired workflow:
Step #1: From a different site subdomain, provide a link to a certain virtual product, but with a query parameter with a unique user id number.
Explanation: The user is at othersite.example.com, and they get a link to buy a product in a WooCommerce store set up with a wordpress site at https://example.com/product/virtual-product
However, this product will be a payment to unlock something on the othersite.example.com site which has its own user and authentication system. (Firebase)
Would it be possible to pass a user id from the othersite.example.com by way of a url query parameter and then have that included in the order info?
ie. From the othersite.example.com someone could be given a link to the product like this https://example.com/product/virtual-product?userid=00000000000000000, with 00000000000000000 being their user id at othersite.example.com.
Then if that userid query value could be included in the order, the following steps should be doable.
Step #2: Have a webhook that fires when the product is purchased, telling a server managing the users for othersite.example.com that the user with userid 00000000000000000 has made a successful purchase of that product.
Is there a way to accept custom values like this to the order? Or is this totally out of the scope of WooCommerce's functionality?
Thanks so much.
I believe that it can be done by using a redirection/link directly to the checkout page, like: "http://yourdomain.com/checkout/?add-to-cart=PRODUCTID&000000" (tested)
In the example, "checkout" stands for the name of your checkout page, "PRODUCTID" stands for the id of desired product, "000000" stands for the user id of redirected person in the other website.
Then you can add a hidden input field to the checkout page (into checkout form, so you will see this value in order) and using the URL you can assign the "000000" (user id) to the value of this field.
I hope that works. If you have any problems with implementation, you can ask me.
- Useful link for hidden input field addition: https://stackoverflow.com/a/42614905/11003615
- Useful link for getting value from current URL using JS: https://web-design-weekly.com/snippets/get-url-with-javascript/
- Useful link for getting value from current URL using PHP/Wordpress Core: https://wordpress.stackexchange.com/questions/274569/how-to-get-url-of-current-page-displayed
- Useful link (contains 4 parts) for adding a custom field to checkout & validating this field & saving this field to order fields & displaying the value of this field in order page: https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/#section-7

Filter collection based on custom dexterity field

I would like to make a collection which returns my custom dexterity type if it's "featured" field is true. I have added this field to the catalog... is there anything else I need to do to be able to see it in the collection search terms?
When you say "I have added this field to the index" you mean to the portal_catalog?
If yes, you must also configure that index as a new collection criteria. If you are using new style collections you need a Generis Setup import step registry.xml. See plone.app.querystring package: https://github.com/plone/plone.app.querystring/blob/master/plone/app/querystring/profiles/default/registry.xml

Symfony2 : datatransformer for child object

Let's say I have Category hasMany Product relation.
Product entity has name and price columns.
The problem:
I want to edit Category entity with its collection of Product entities using data transformers. For example:
Edit form is empty. I click on "add product", javascript would call ajax and new Product will be created. That newly created product has id that will be injected into the main form (as hidden), together with field for name and price.
So I need transformer that will understand the hidden ID and edit name and price on that object.
What I have is kinda big code and Symfony tries to create new object.
NOTE:
I am aware how to work with collections but my real relation is not as in this example and javascript/ajax must create new Product.

Drupal Views Content Profile User as an argument

I have a normal Drupal User. I have used the content_profile module to create a profile content type. This content type contains a node reference to another content type company. The company node then references a type of node called Task.
I want to create a view that list all the tasks for a given user id.
So I imagine I would create a view with an argument of user id. Then I would add the relationship to the profile and the company and output the Task title.
The user id used seems to work on the created used ID and not the user id of the content profile that it is referencing. In our system the "admin" user creates the profiles so it causing some problems.
Any ideas? I feel I may need to write a custom module to do what I want.
i have answered a similar question in the past about how to create a view using part of the url as an argument to filter the view by the user profile. check out this url. the answer you are looking for may be a variation of my original response.
also, how are you creating those profiles? on one of my sites, when i created the profile page, its author ID is automatically changed to the user it is associated with.

Many-To-One relationships in NHibernate

I am still trying to learn NHibernate best practices, so please be easy on me... :-)
I have a Product class with a Many-To-One relationship set up to a Category class. On my Add A Product page, I am loading a DropDownList with the Categories. Now when the user enters the product information and clicks submit, I have to pull down the Category by ID (DropDownList SelectedValue) from the database to populate the Category property of my Product object so I can save it.
It seems like the Category by ID lookup is a waste. Is there a way I can simply use the ID value that was retrieved from the DropDownList?
Thanks for any advice!
Use ISession.Load() to create a proxy object. eg:
myProduct.Category = session.Load<Category>(userSuppliedCategoryId);
Note that the Load() method doesn't actually hit the database unless you try accessing a property besides the primary key, so there is no extra DB hit.
Ayende has a good post about this

Resources