How to modify the Product default URL automatically?

What we would like to change to is:

When admin create a new product in MarketPress, the URL of the new product will have the blog ID and product ID at the end of the URL, such as:
http://www.domain.com/store/product/this-is-a-new-product-6-32

The first number is blogID 6, and the second number is productID 32.

Both numbers are all known at the time when "publish" button is pressed. I assume we just read it out somewhere and then change the URL accordingly. Am I right?

In summary,
1. How to get the blog ID and proudct ID automatically when creating a new product in marketpress?
2. How to change the new product URL to add blog ID and product ID at the end automatically?

Can this be done easily? Where do we start?

Thank you for reading my question :slight_smile:

Note: if you are really curious why we need that, here is the short story:slight_smile:
We will display some of the facts of this product on the front end, such as total number of sales to-date. In order for us to read out this piece of information from the store database, we need to know the blog ID and product ID. We could find out both IDs manually for each product, but it would be time consuming if we have to do that all the time for all the products. So, an automation would be nice. Would you think :slight_smile:

  • DavidM
    • DEV MAN’s Mascot

    Hi winning,

    I think you can use the snippet provided in the following from stackexchange to help achieve that:
    http://wordpress.stackexchange.com/questions/18107/how-can-i-automatically-set-a-post-slug-based-on-the-post-title-during-post-publi

    However, it relies on coding a solution and as such, I think it would be much simpler to get the blog id and product id programmatically rather than have it tacked on to the product urls, no?

    If you take a look at the various functions provided in marketpress-includes/template-functions.php and perhaps the various gateways, especially regarding the cart, you can see how to get the blog id to which a product belongs. The product id is how the products are referred to in all that code.

    Perhaps that would work better for your purposes?

    It actually comes down to a matter of custom work though, either way, not something we can really provide by way of support, but happy to point you in the right direction!

    -David

  • winning
    • The Incredible Code Injector

    Hi David, That is exactly the direction I needed and got it now. Thank you!

    About the URL idea, if we could programmatically figure out the blog ID and product ID given a product URL, we do not have to tack it in URL. Any possible solution?

    Actually the real URL should be: (I missed the sub blog name in preview post)

    http://www.domain.com/sub-blog-name/store/product/this-is-a-new-product-6-32

    The only reason to put both IDs in URL when creating the new product is - at that moment, both IDs are being used/generated and saved in the database, so they are availalbe at the finger tips, if we can record both IDs at that point and put in it URL, we have the URL carring the IDs everywhere. Whenever we need it, it is there. However, if one can tell the blog ID and product ID by just using the standard URL, it wold definitely be a better solution.

    Standard URL: http://www.domain.com/sub-blog-name/store/product/this-is-a-new-product

    Any idea?

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.