Magento 2 simple product details on parent page - php

I would need some help.
I need to create a custom thing on configurable products that is also seo friendly.
In my case I have a configurable product with 4 options which are simple products that are not visible. In case my customer clicks one of these options on page the info is updated and the url is also changed.
And here is the problem, in case the user reloads the page, it obviously responds with 404 since the product is not reachable.
I would need to then create the ability to redirect on the parent keeping the child url and then pre-select the infomation.
Adding that the pre-select is not a problem, I am using the X event to hook to the controller but I cannot in any way change the url.
Could you maybe help me or in case direct me?
Thanks

Hi Guys I answered myself. To get around this problem I create rewrite urls at the prototto jump of my case history where the child fake url points to the parent

Related

How can I create a wordpress detail page?

I've a Wordpress site page (5.7 version) called Ranking with all athletes showed (url = "https://example.com/ranking").
For every athletes showed I create a button link for display all athlete details.
What I would like is that by clicking button (for example athleteId=2352), the page to open will be = "https://example.com/athlete/2352.
How can I create athlete page?
Do I change only permalink?
Do I Have to rewrite my theme rules?
Thanks
Look into creating a custom post type for the purpose. You should then have control of rewrite rules, archive slug etc.
https://developer.wordpress.org/reference/functions/register_post_type/
And as ed2 mentions, please be more clear in your questions. It makes it easier to help out, and more useful for others with the same issue as yourself

How to change a URL for a specific page in WordPress?

I'm not talking about site URL.
I mean like changing from mysite.com/our-team/john-doe to mysite.com/our-volunteers/john-doe
I just want to rename the /our-team/ to /our-volunteers/. There's only one john-doe page. Now, John Doe is NOT our team per se, but he's a volunteer. So, I need to change the slug to "our volunteers."
The current premium I'm using does not create a WordPress typical page for this so I can't modify the url of the page. So, this does not work -> https://www.competethemes.com/blog/change-page-url-wordpress/
Is there like a hook i can use? Permalinks only allow changing the url structure of the entire site.
What you exactly looking for is Page attributes
https://wordpress.com/support/pages/page-options/#parent-page
You have parent page Our volunteers
http://example.com/our-volunteers
And pages of children pages
http://example.com/our-volunteers/john-doe
http://example.com/our-volunteers/foo
http://example.com/our-volunteers/bar
Set our-volunteers as page slug when you create Our volunteers page
Assign pages John doe, foo, bar to Parent page (Our volunteers) from Page attributes section bottom right on 'creating new page' page
One hack could be to edit .htaccess for this particular issue. It's kinda hacky and might get you into other problems. There's also plugins to do rewrites for you.

Wordpress create custom pages with permalinks from custom table data

I have 1 custom table (not wp core table) where are specific products imported. I've set up custom wp page where these products are listed, custom filter created etc. In this step so far everything is OK - products are listed and filtering works, pagination works...
But what I want to extend further now - open each product page (like /product-listing-page/product-name-1) when clicking on product names in product list page... How can be this achieved "out of wp_posts" table?
Why I'm not using wp_posts table: web site have static pages and dynamic posts as news and product table is truncated and re-imported once in a day every night! So, can not really use wp_posts page when product list is dynamic and totally truncated before each import...
Any ideas? Maybe anybody already did such stuff?;-)
I don't know if you developed a plugin to handle all the custom table and code you created, but if you didn't, I strongly encourage you to do so.
Because by making your code as a plugin, you have the oportunity to use all the composants of wordpress, like the rewrite rules system, which, I think, could help you to achieve your goal.
I created a plugin some times ago for a website I have the charge and I needed a custom page to be displayed within the website (worpdress) url system, which is what you want to do if I correctly understand your question.
Unfortunately the plugin has evolved since and I didn't keep a backup of that code, but if I remember correctly how I did it back when, here is the rough approach I followed:
I create a plugin which handle :
custom db table(s)
custom php objects
...
AND (this is the intersting part) add rewrite rule to wordpress rewrite rules system as follow:
set rewrite tag (init action) (if needed)
add rewrite rule (init action)
intercept url and parse it to get the params i need in my custom
page (parse_request action)
The following functions may help you with that :
add_rewrite_tag
add_rewrite_rule
And you need to hook in :
init
parse_request
Hope it helps you start.
the solution was quite quick and easy! For my needs it was enough just to register global query var:
function register_new_query_var($vars) {
$vars[] = 'product_id';
return $vars;
add_filter('query_vars', 'register_new_query_var');
and then I changed theme template for page product-listing-page to work for product listing and individual products with using
if(!get_query_var('product_id')). So, if query empty - do listing stuff, if not empty - do individual product stuff!
For me this is quite enough and I do not need even seo friendly urls (because product list changes every day, so - every day will be new products, links, and there will be to much 404 errors)...
and I can use http://example.com/product-listing-page?product_id=1 and page displays with date which is from custom table! ;-)

list all products and link each category grid with category box in opencart

I want to load all categories grids on one page and want all products to be available on scroll down. currently I need to click on each category and the page refreshes for each category. This is the site I am working on(ahmad.esy.es). I want this type of functionality upon clicking the category(http://www.just-eat.co.uk/restaurants-hertsplaice-en11/menu#2254). kindly suggest me what changes should I make in view files (product.tpl, category.tpl) or controller files(product.php, category.php). how can I load all the grids of categories in one page
I didn't look at the site you have posted above - if you cannot describe your issue by words or by submitting a code or image it should be improved.
From what I understand you just want an infinite scroll to display all the products you have in your eshop. It is not mentioned whether you want to preserve the default functionality (category tree with products attached to certain categories) or whether you want only this one listing - basically it does not matter - so I will describe in short how to add such new functionality.
The model
you do not need to touch any model - you can reuse the method ModelCatalogProduct::getProducts()
this will give you the possibility to sort or filter the products except you will have to omit the filter_category_id to load all the products
The controller
feel free to create a new controller (e.g. ControllerProductInfinite) or just to reuse one of the already existing - either ControllerProductCategory or ControllerProductProduct
all you need is basically the same as in ControllerProductCategory::index() except adding filter_category_id into a array passed when calling ModelCatalogProduct::getProducts() and a new template for rendering
The template
create a new template that will meet your expectations and infinite scroll requirements
stick to any infinite scroll plugin/implementation you like (may Google be with you)

block access to certain pages in magento

i have a category in my store, lets call it Program, this category will only have 1 product, lets call it Program product, so, i've developed a module only to show this category and product, the view is diferent from the others categories, so, if i write in my browser the url
myweb.com/index.php/program.html or myweb.com/index.php/program-product.html i can see the custom categories page or the product view page and i don't want that, i want that if someone write this url he will be redirect to another one, how can i do that, if it is posible
thanks
"Do you want the category to show in the category menu but link to your new URL and not show in the old one?"
"yeah, this is exactly what i want, is this possible??"
Try this; Go to the menu Catalog > URL Rewrite Management and find the entry for your category. Crucially it's target path will look something like "catalog/category/view/id/123" ('catalog' is the module, 'category' is the controller, 'view' is the action and 'id/123' is a parameter).
Follow these URL rewrite instructions to delete the above entry then create a replacement. It's only difference will be the target path, use your module's path along with whichever controller, action and parameters are suitable for this case.
By preserving the ID Path of the old rewrite rule you are ensuring it doesn't get overwritten, although I haven't tested this with rebuilding indexes.
Does the category's enabled setting, and the product's visibility setting affect your module's display? If not use those settings to hide them from the catalog but continue using your module as normal.

Categories