Magento sorting in cateory listing page - magento-1.7

I got the following code here:app\code\core\Mage\Catalog\Block\Product\List\Toolbar.php and i got the following function.
Can we add more code here to solve the issue.:--
Products should sort like:-
Products Name: Prices
A: $200
BC: $200
B: $100
BD: $100
CD: $100
C: $99
public function setCollection($collection)
{
$this->_collection = $collection;
$this->_collection->setCurPage($this->getCurrentPage());
// we need to set pagination only if passed value integer and more that 0
$limit = (int)$this->getLimit();
if ($limit) {
$this->_collection->setPageSize($limit);
}
/* if ($this->getCurrentOrder()) {
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
} */
if ($this->getCurrentOrder()) {
if(($this->getCurrentOrder())=='price'){
$this->_collection->setOrder('entity_id','asc');
}
else {
$this->_collection->setOrder($this->getCurrentOrder(),$this->getCurrentDirection());
}
}
return $this;
}
I want to display products listing of category from high to
low price if prices of all the products are same then all the products will be shown alphabetically by default on page load.

Yes i got the answer:
public function setCollection($collection)
{
$this->_collection = $collection;
$this->_collection->setCurPage($this->getCurrentPage());
// we need to set pagination only if passed value integer and more that 0
$limit = (int)$this->getLimit();
if ($limit) {
$this->_collection->setPageSize($limit);
}
if ($this->getCurrentOrder()) {
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
}
if ($this->getCurrentOrder()) {
if($this->getCurrentOrder()=='price')
{
$this->_collection->setOrder('price','asc');
$this->_collection->setOrder('name','asc');
}
}
else {
$this->_collection->setOrder($this->getCurrentOrder(),$this->getCurrentDirection());
}
return $this;
}

Related

Prioritizing Constraints in linear SolverContext Model using SolverFoundation

Good morning,
I am trying to solve what I believe is a linear problem, using Microsofts SolverFoundation in code (c#). I see most references to this type of solving are related to the Solver inside of Excel, and it indeed does share many similarities. However, I have written up an example of what I am trying to do.
For this example, lets say I have 3 grocery stores (Albertsons, Safeway, Costco), and 3 different types of apples (Red, Green, Fuji).
public enum AppleType
{
Red,
Green,
Fuji,
}
Each of these stores offers these different apple types at different percentages per order.
public class Store
{
public string Name { get; set; }
public List<Apple> ApplesOffered { get; set; }
}
public class Apple
{
public AppleType AppleType { get; set; }
public double OrderPercent { get; set; }
}
Here is my mock-data for this setup.
List<Store> stores = new List<Store>
{
new Store()
{
Name = "Albertsons",
ApplesOffered = new List<Apple>
{
new Apple(){AppleType = AppleType.Red, OrderPercent = 80 },
new Apple(){AppleType = AppleType.Green, OrderPercent = 15 },
new Apple(){AppleType = AppleType.Fuji, OrderPercent = 0 }
}
},
new Store()
{
Name = "Safeway",
ApplesOffered = new List<Apple>
{
new Apple(){AppleType = AppleType.Red, OrderPercent = 12 },
new Apple(){AppleType = AppleType.Green, OrderPercent = 30 },
new Apple(){AppleType = AppleType.Fuji, OrderPercent = 0 }
}
},
new Store()
{
Name = "Costco",
ApplesOffered = new List<Apple>
{
new Apple(){AppleType = AppleType.Red, OrderPercent = 10 },
new Apple(){AppleType = AppleType.Green, OrderPercent = 35 },
new Apple(){AppleType = AppleType.Fuji, OrderPercent = 40 }
}
}
};
Alright, so say I have a list of apple types and I want to choose how many of each I want, and the solver should give me the minimal optimized orders from different stores to get what I want.
my code for building the constraints is as follows:
var context = SolverContext.GetContext();
context.ClearModel();
var model = context.CreateModel();
// Decisions
stores.ForEach(store => model.AddDecisions(new Decision(Domain.RealNonnegative, store.Name)));
// Constraints
var constraints = new List<CustomAppleConstraint>();
stores.ForEach(store =>
{
foreach (AppleType a in (AppleType[])Enum.GetValues(typeof(AppleType)))
{
var ao = store.ApplesOffered.FirstOrDefault(_ => _.AppleType == a);
if (ao != null && ao.OrderPercent > 0)
{
constraints.Add(new CustomAppleConstraint
{
Type = a,
Value = $"0.{ao.OrderPercent} * {store.Name}"
});
}
}
});
// Add Constraints to model
var constraintGroups = constraints.GroupBy(_ => _.Type).ToList();
foreach (AppleType a in (AppleType[])Enum.GetValues(typeof(AppleType)))
{
var group = constraintGroups.FirstOrDefault(_ => _.Key == a);
if (group != null)
{
model.AddConstraint($"_{a}", $"{(string.Join(" + ", group.Select(_ => _.Value).ToArray()))} >= {order[a]}");
}
}
// Solve
var solution = context.Solve(new SimplexDirective());
var solutionResults = new List<KeyValuePair<string, double>>();
foreach (var decision in solution.Decisions)
{
var value = (double)decision.GetValues().First()[0];
solutionResults.Add(new KeyValuePair<string, double>(decision.Name, value));
}
return solutionResults;
I have tested this with a bunch of different orders, and it all appears to be giving me the correct data.
Now say I have the following simple order where I only want green apples:
{AppleType.Red, 0},
{AppleType.Green, 10},
{AppleType.Fuji, 0}
I get back a result suggesting 28.57 orders from Costco, which I would expect because Costco offers the highest percentage of green apples per order.
So here is where I am trying to figure the correct way to implement one more constraint.
Say I have some preferences for which stores I use to get certain apple types. (eg, I only want my green apples from Safeway).
// Apple Type : Preferred Store
var orderPrefs = new Dictionary<AppleType, string>()
{
{AppleType.Red, "Albertsons"},
{AppleType.Green, "Safeway" },
{AppleType.Fuji, "Costco" }
};
So even though Costco provides the highest percentage of green apples, I want to add some constraints from my preferences that prioritize the green apple result from Safeway. In this instance, my prefs say I Only want green apple from Safeway, so 100% of this order should come from Safeway.
Granted this is a very simple example, but its the meat of what I am trying to wrap my head around.
I hope this makes sense... I have been trying to figure this out for a few days now with no luck. Thank you.

How to get ag-grid table to break up an array of strings into multiple rows in same column

Learning ag-grid and ran into this issue. Calling a service to fill in a table. But my last column "Mode" returns an array. I want that to be broken so "Mode1" is on first row. Then "Mode2" on second row. All the previous columns for can be blank on the "Mode1" row.
Currently it print out Mode1Mode2 cause I concatenate the mode strings on the first row. I did use a rowspan that does evaluate to 2. But not sure how to force it to force the text to actually take advantage of that. Any help is appreciated and thank you.
public columnDefs;
public defaultColDef;
public rowData: DataObj[];
public title = 'Grid';
constructor(private service: DataService) {
this.columnDefs = this.createColumnDefs();
}
// on init, subscribe to the athelete data
ngOnInit() {
this.service.loadProcesses().subscribe(data => {
this.rowData = data;
console.log('data',data);
},
error => {
console.log(error);
}
)
}
onGridReady(params) {
this.gridApi = params.api;
this.gridColumnApi = params.columnApi;
this.gridApi.sizeColumnsToFit();
} // on GridReady ends here
private createColumnDefs(){
return [
{ headerName:"IDs", field:"id", width:80 },
{ headerName:"Process", field:"content", width:120,rowSpan: calculateRowSpan },
{ headerName:"Requirement", field:"req", width:160,rowSpan: calculateRowSpan },
{ headerName:"Comment", field:"comment", width:120,rowSpan: calculateRowSpan },
{ headerName:"Mode",
field:"fModes",
valueGetter: function generateModeField(params) {
let modesCount = params.data.fModes.length;
let returnValue = '';
for (let x=0;x<modesCount;x++){
returnValue = returnValue + params.data.fModes[x].name;
}
return returnValue;
},
rowSpan: calculateRowSpan,
width:200 }
];
}
Notice it takes up rowspan of 2

TYPO3 backend user right for columns

I would like to assign BE User rights to specific columns in BE Layout (Field colPos): A usergroup shall not be able to edit one column.
Any ideas?
use condition in page tsconfig:
[usergroup = 2]
mod {
web_layout {
BackendLayouts {
standard {
config {
backend_layout {
rows {
1 {
columns {
1 {
colPos =
}
}
}
}
}
}
}
}
}
}
[global]

concat results of select with complex types

I have bellow class :
public class KardeksKalaComplexColumnInfoM{
private decimal _Qty;
public decimal Qty
{
get { return _Qty; }
set
{
if (_Qty != value)
{
_Qty = value;
this.RaisePropertyChanged("Qty");
this.RaisePropertyChanged("Total");
}
}
}
private decimal _Fee;
public decimal Fee
{
get { return _Fee; }
set
{
if (_Fee != value)
{
_Fee = value;
this.RaisePropertyChanged("Fee");
this.RaisePropertyChanged("Total");
}
}
}
public decimal Total
{
get { return Qty * Fee; }
}
}
and a context contains buys and sales,i run bellow code and results commented in three last lines:
var q_buys = (
from
r_d in _db.BuyDetails
select new KardeksKalaDetailM()
{
ID = r_d.ID,
Date = r_d.Date,
in = new KardeksKalaComplexColumnInfoM() {Qty = r_d.Qty, Fee = r_d.Fee },
});
var q_sales = (
from
r_d in _db.SaleDetails
select new KardeksKalaDetailM()
{
ID = r_d.ID,
Date = r_d.Date,
in = new KardeksKalaComplexColumnInfoM() { Qty=0 , Fee=0 },
});
var q1=q_buys.ToList(); // Ok
var q2=q_sales.ToList(); // Ok
var result=q_buys.Concat(q_sales).ToList(); // Error
when I change the KardeksKalaComplexColumnInfoM filed types to double the last line's error solved but when them types are decimal it has bellow error:
An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code
Additional information: The specified cast from a materialized 'System.Int32' type to the 'System.Int64' type is not valid.
how can resolve last line problem?

Typo3: Repository->findAll() returns only one entry

I have created an extbase extension, using the extension builder.
But when i call findAll() it returns the first row of the mapped table, but again and again. The number of results is correct but all of them are only the first row.
Mapping:
config.tx_extbase {
persistence {
classes {
Vendor\ExtName\Domain\Model\Word {
mapping {
tableName = table_name
columns {
id.mapOnProperty = id
string.mapOnProperty = string
}
}
}
}
}
}
listAction():
public function listAction() {
$words = $this->objRepository->findAll();
$this->view->assign('obj', $objects);
}