For example, here is url
http://www.tiffosi.com/mulher/camisas-e-tunicas/blusa-l-s-93368.html.
There are several simple products. How can I get the actual simple product ID, from this url?
Magento 1.8
First use the URL rewrite model to find the route which matches your product:
$vPath = 'http://www.tiffosi.com/mulher/camisas-e-tunicas/blusa-l-s-93368.html';
$oRewrite = Mage::getModel('core/url_rewrite')
->setStoreId(Mage::app()->getStore()->getId())
->loadByRequestPath($vPath);
Then you can call getProductId() on the route to locate the produc's id:
$iProductId = $oRewrite->getProductId();
Finally if you require the product model object itself it's then a simple matter to call:
$oProduct = Mage::getModel('catalog/product')->load($iProductId);
Related
I'm building a website for a client, he wants to update his stock from his Presta website to his CRM. In order to achieve that it's very simple, I only have to call an URL like this :
http://crm.com/client1/bin/majstock.php?mode=stock&pdt=REF~-1;REF2~-1
Where REF is obviously the Ref of the product, and the number after ~ is the quantity to update, so in this example the customer bought 2 products, one is REF and the other one is REF2.
The problem is that I don't know where I should call this URL, and where I can get the parameters
Thanks for your help !
You can use the hook actionOrderStatusUpdates like that:
public function hookActionOrderStatusUpdate($params)
{
$OrderState = $params['newOrderStatus']; // an OrderState object
// $OrderState->id // order status ID
// $params['id_order'] // order ID
$Order = new Order((int)$params['id_order']);
$products = $Order->getProductsDetail();
// or
$products = $Order->getProducts();
}
You could create a new module with a hook on actionOrderStatusUpdate and call the CRM when the desired status is set on the order.
I have an application which I am trying to build using Slim PHP and at the moment I am struggling with one Route I am trying to sort out. Basically what happens is I go to GET /:slug and this provides me with a product view. However if there are variations on this product, it will be an intro page in which a visitor can target an exact product. The differences in these products will be :
Color
Dial
Strap
Material
Possibly a few others. The problem I am having is that I am not 100% sure which if any there will be. Do I write my routes for every possibility? Or is there a way I can get this to take a more relaxed approach to how this is formed?
I saw an example where someone did the following :
$app->get("/:slug(/:dial(/:strap(/:material)))", "Route\To\Controller:Action");
However I am assuming this will require this to be in that set order?
Also a note to add would be that some products have no additional filters and respond directly to /:slug whereas others may require all of the additional filters.
These results are all set in the database. I grab all products that have a similar slug as it equates to the product name, then each filter or collection of filters will be determined by certain parts in the database. For example: /this-product/this-dial/this-color/this-strap/this-material all of these values will be stored within the database table for the product - they either have a corresponding value for material - or it is NULL.
This allows me to on the root URL with the SLUG I can show variations - which will aid in the shopping experience in my opinion.
Does anybody have a solution?? Anyway I could achieve this? Am I going about it the wrong way?
One possible way is to render different templates based on the number of returned products. For example, if you are using Twig Template extension you can easily iterate over the set of results and render two templates one for Product Description and one for Product Group.. Alternatively, You can handle this while rendering a view in your SLIM Route
$app->get('/:slug', function ($slug) use ($app) {
$db = new dbConn();
$Products = $db->ProductQuery(); // DB querying for 'slug' & returned product (s)
if( // here check how many $Products and if = 1 ) {
$app->render('single_product_view.html',$Products);
} else if( /// > 1 ) {
$app->render('multiple_product_view.html',$Products);
} else {
$app->response->redirect($app->urlFor('notFoudnt'), 404); // or whatever other route..
}
})->name("product");
As for the querying why do you want to have a route for each product attribute ?
Can't you in this case have one route for the product view and add a query parameter ( attributes ) to URL
/this-product?dial=this-dial&color=this-color&strap=this-strap&material=this-material
$app->get('/:slug', function ($slug) use ($app) {
$Dial = $app->request()->get('dial');
$Color = $app->request()->get('color');
$Strap = $app->request()->get('strap');
$Mat = $app->request()->get('material');
// same as above, build your query string and render corresponding view
})->name("product");
You can also Group your routes ( for ajax request maybe.. )
$app->group('/api', function () use ($app) {
// Products attributes group route
$app->group('/products', function () use ($app) {
// Get Products with color = :color /api/products/color/:color
$app->get('/color/:color', function ($color ) {
});
// Get Products with Strap = :strap /api/products/strap/:strap
$app->get('/strap/:strap', function ($strap) {
});
// and so on..
});
});
I'm completely new to ci,
I have a url something like this:
http://localhost/mvc/post/prod_id/1
And I want it to be:
http://localhost/mvc/post/my-best-product
So far I'm able to manage to route all that to home/post/ and learned the segment function also.
But my question is how do I really get the url_title out to the actual url.
I couldn't find any information on this particular subject. All I could find is how to use the url_title and how to route in ci. But they don't explain how we can actually change the base url name.
Please guide me to the right direction.
solution Example:
public function my_method($product_slug)
{
$product1 = "training-for-recruitment";
$product2 = "training-for-od";
if($product_slug==$product1)
{
$this->load->view('prod1');
}else if($product_slug==$product2)
{
$this->load->view('prod2');
}else{
show_404();
}
}
This is not what exactly I'm going to do. It is just for others to understand the workaround of Slugs.
Generate a unique slug for each of your product. Add a field for it on product table and every time, while selecting a product from table, use that slug instead of getting the product from primary id.
So, your function becomes like:
function product($product_slug)
{
//get product by slug from database
//load view page
}
Now, in config/routes.php
$route['your_controller_name/(:any)'] = "your_controller_name/product/$1";
You need to do this:
Set up some logic that translates "my-best-product" to "1"
Set up routing in CI that calls your 'prod_id' controller and passes the URI vars
My problem is the following: Magento creates URL rewrites for new products and uses different URLs on different listings. If my product is in two categories Foo and Bar, Magento will use two URLs on top of the one I actually want.
In category listing Foo => /store/type/foo/product.html
In category listing Bar => /store/type/bar/product.html
In normal linking /store/product.html
I want/need to get Magento to use only the URL /store/product.html throughout the entire store. I have not found any setting in the admin pages for that.
Using Magento 1.5.1.0.
Change "Use Categories Path for Product URLs" property in System -> Configuration -> Catalog to "No".
For some reason, Magento ignored the setting for all the stores. After searching the code, I found that the method Mage_Catalog_Model_Product_Url::getUrl() checks this setting with $product->getDoNotUseCategoryId(). I called this method, and it returned NULL for all the products.
To solve this, I overloaded this method in my own product class:
public function getDoNotUseCategoryId(){
return true;
}
This works.
It might be a problem with a non-existent attribute or something, but as long as this works I'll use it.
There is one simple way to do this for every where, copy Url.php from app\code\core\Mage\Catalog\Model\Product and past URl.php into app\code\local\Mage\Catalog\Model\Product. After that need to update getUrl function.
Find this line: $categoryId = $product->getCategoryId() && !$product->getDoNotUseCategoryId()
? $product->getCategoryId() : null; and update with $categoryId = $product->getCategoryId() && Mage::getStoreConfig('catalog/seo/product_use_categories')
? $product->getCategoryId() : null;
Hope this will help someone.
I am trying to get the product attribute in my downloadable controller. I am working on an ebook store. I have created a custom module sp. I need the product attribute to watermark my ebooks.
The controller I am working on is Mage/Downloadable/controllers/DownloadController.php
Any suggestions?
Thanks.
Depends totally in which action you are.
If you have a look at the linkAction you can see how they obtain the product:
$id = $this->getRequest()->getParam('id', 0);
$linkPurchasedItem = Mage::getModel('downloadable/link_purchased_item')->load($id, 'link_hash');
[...]
$product = Mage::getModel('catalog/product')->load($linkPurchasedItem->getProductId());
Now the product is loaded in the $product variable.
You can get product attributes as usual by $product->getData('my_custom_attribute') or $product->getMyCustomAttribute.