Querying package-weight property on basket
Posted: 24 Sep 2015, 12:43
Hi,
I´m trying to qery the basket weight property but can´t manage to setup a query taht is selecting the property value directly. As you can see I am currently looping over all properties to get the one in question:
What am I missing here?
Best
Robert.
I´m trying to qery the basket weight property but can´t manage to setup a query taht is selecting the property value directly. As you can see I am currently looping over all properties to get the one in question:
Code: Select all
/**
* Returns the weight dependend price
*
* @param MShop_Order_Item_Base_Interface $basket Basket object
*
* @return MShop_Price_Item_Interface Price item containing the price, shipping, rebate
*/
public function calcPrice(MShop_Order_Item_Base_Interface $basket) {
$config = $this->getServiceItem()->getConfig();
$context = $this->_getContext();
$basketWeight = 0;
$basketItems = $basket->getProducts();
foreach ($basketItems as $basketItem) {
$propertyManager = MShop_Factory::createManager($context, 'Product/Property');
$search = $propertyManager->createSearch(true);
// $expr = array(
// $search->compare('==', 'product.property.type', 'package-weight'),
// $search->getConditions(),
// );
// $search->setConditions($search->combine('&&', $expr));
$properties = $propertyManager->searchItems($search);
foreach ($properties as $property) {
if ($property->getType() == 'package-weight') {
if ($property->getValue() > 0) {
$basketWeight += $property->getValue() * $basketItem->getQuantity();
}
}
}
}
foreach ($config as $key => $costConf) {
if ($basketWeight > (float) $costConf['min'] && $basketWeight <= (float) $costConf['max']) {
$cost = $costConf['cost'];
}
}
$price = $this->_getProvider()->calcPrice($basket);
$price->setCosts($cost);
return $price;
}
Best
Robert.