Prestashop custom layout for specific category - smarty

Can I have a specific category layout for selected categories? The detail page will be the same, I need to get a custom tpl file.
Thanks for suggestions

Pretty easy to do: override the category controller to set the template.
class CategoryController extends CategoryControllerCore {
// array with the selected categories
private $customCategories = array(1, 3);
public function init() {
parent::init();
if (in_array($this->category->id, $this->customCategories)) {
$this->setTemplate(_PS_THEME_DIR_.'category-custom.tpl');
}
}
}
Here you wouldn't be able to change the selected categories from the back office, but it would be easy to do with a module.

Related

How to include two controller in url in codeigniter 3?

I want to include two controller in a url. Ex. domian.com/category/js/topic/promise. In this, category and topic are controllers and js is argument of category controller, and promise is argument of topic controller.
I have searched, and doesn't found any related example like it. So, How can I achieve this type of url which contains two controller url? I am using codeigniter 3.
/* code of category controller*/
class Category extends MY_Controller{
public function index($category = null){
if($category == null){
// here show all categories using model
}
else{
// show topics of given category
}
}
}
/* code of topic controller */
class Topic extends MY_Controller{
public function index($topic = null){
if($topic == null){
// here show all topics using model of the selected category
}
else{
// show data of selected topic
}
}
}
To use your Topic/index method with your desired url structure, you need to add the following to config/routes.php:
$route['category/(:any)/topic/(:any)'] = "topic/index/$2";
domain.com/category will then show all categories
domain.com/category/index/js will show all topics in a specific category
domain.com/topic will show all topics in all categories
and both domain.com/category/js/topic/promise and domain.com/topic/index/promise will then show a specific topic
If you also need to access the selected category in Topic/index, add it as an argument:
class Topic extends MY_Controller{
public function index($topic = null, $category = null){
if($topic == null){
// here show all topics using model of the selected category
}
else{
// show data of selected topic
}
}
}
And change the route to pass the category from the url onto the method:
$route['category/(:any)/topic/(:any)'] = "topic/index/$2/$1";

Change default product listing direction for some categories

I need to change the default product listing direction on some category list pages. As you know there is no such option Magento admin, so I need to do this programmatically.
Categories that needing product sort direction override is a sub-category of another category, let's call that parent category ID 1.
How can I override category 1's all children categories' default sort order?
You can change in function in this location
app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php
If you get Here category then set direction as per your requierement.
public function setDefaultDirection($dir)
{
if (in_array(strtolower($dir), array('asc', 'desc'))) {
$this->_direction = strtolower($dir);
}
return $this;
}

.net mvc partial for showing child elements that exist in different models

I have an application that has products. Each product belongs to a brand and a category.
I have my models structured so when I get a category or brand, all the products within either are returned as an IEnumberable.
How do I create on partial view that I can use in either my main brand or category view that will display the products no matter what the current model is?
Thanks in advance.
Have a view which is strongly typed to List of Product and keep it under a shared location. (~/Views/Shared folder with a name ProductList.cshtml)
#IList<Product>
#{
Layout=null; //assuming this is for ajax (Popups).so no layout needed.
}
#foeach(var prod in Model)
{
<p>#prod.Name</p>
<p>#prod.Price</p>
}
You can use this view to show list of Product, no matter it belongs to brand / category /whatever
public ActionResult ShowProductsForBrand(int brandId)
{
List<product> products=GetProductsForBrand(brandId);
return View("~/Views/Shared/ProductList.cshtml",products)
}
public ActionResult ShowProductsForCategory(int catId)
{
List<product> products=GetProductsForCategory(catId);
return View("~/Views/Shared/ProductList.cshtml",products)
}

MVC3 Razor - Models and Views

I have an action that creates a List and returns it to my view..
public ActionResult GetCustomers()
{
return PartialView("~/Views/Shared/DisplayTemplates/Customers.cshtml", UserQueries.GetCustomers(SiteInfo.Current.Id));
}
And in the "~/Views/Shared/DisplayTemplates/Customers.cshtml" view I have the following:
#model IEnumerable<FishEye.Models.CustomerModel>
#Html.DisplayForModel("Customer")
Then I have in the "~/Views/Shared/DisplayTemplates/Customer.cshtml" view:
#model FishEye.Models.CustomerModel
#Model.Profile.FirstName
I am getting the error:
The model item passed into the dictionary is of type System.Collections.Generic.List`1[Models.CustomerModel]', but this dictionary requires a model item of type 'Models.CustomerModel'.
Shouldn't it display the Customer.cshtml for every item in the collection in the Customers.cshtml?
Help!
I am not sure why you are calling a partial view like this. If it is a Customer Specific view, why not put it under Views/Customer folder ? Remember ASP.NET MVC is more of Conventions. so i would always stick with the conventions (unless abosultely necessary to configure myself) to keep it simple.
To handle this situation, i would do it in this way,
a Customer and CustomerList model/Videmodel
public class CustomerList
{
public List<Customer> Customers { get; set; }
//Other Properties as you wish also
}
public class Customer
{
public string Name { get; set; }
}
And in the action method, i would return an object of CustomerList class
CustomerList customerList = new CustomerList();
customerList.Customers = new List<Customer>();
customerList.Customers.Add(new Customer { Name = "Malibu" });
// you may replace the above manual adding with a db call.
return View("CustomerList", customerList);
Now there should be a view called CustomerList.cshtml under Views/YourControllerName/ folder. That view should look like this
#model CustomerList
<p>List of Customers</p>
#Html.DisplayFor(x=>x.Customers)
Have a view called Customer.cshtml under Views/Shared/DisplayTemplates with this content
#model Customer
<h2>#Model.Name</h2>
This will give you the desired output.
Your view is expecting a single model:
#model FishEye.Models.CustomerModel // <--- Just one of me
You're passing it an anonymous List:
... , UserQueries.GetCustomers(SiteInfo.Current.Id) // <--- Many of me
You should change your view to accept the List or determine which item in the list is supposed to be used before passing it into the View. Keep in mind, a list with 1 item is still a list and the View is not allowed to guess.

setProduct($product) Calling the Super Product Attributes

I am using the Simple Configurable Products extension by OrganicInternet.
I have a number of Tabs in every product with related information.
I am editing OrganicInternet/SimpleConfigurableProducts/Catalog/Block/Product/View/Type/Configurable.php
The logic is as follows -- (this builds the JSON with the simple products data):
class OrganicInternet_SimpleConfigurableProducts_Catalog_Block_Product_View_Type_Configurable
extends Mage_Catalog_Block_Product_View_Type_Configurable
{
public function getJsonConfig()
{
$config = Zend_Json::decode(parent::getJsonConfig());
$childProducts = array();
....
foreach ($this->getAllowProducts() as $product) {
.....
if (Mage::getStoreConfig('SCP_options/product_page/change_attributes')) {
$childBlock = $this->getLayout()->createBlock('catalog/product_view_colors');
$childProducts[$productId]["colors"] = $childBlock->setTemplate('catalog/product/view/colors.phtml')->setProduct($product)->toHtml();
}
......
}
The block is rendering properly, but for some reason it is not using the correct Product. I suspect the setProduct($product) method is not working. (It is using the "super" product), but when I do a print_r(get_class_methods($product)), it shows the correct simple product.
Any ideas?

Resources