09-04-2018, 03:42 AM
|
|
|
|
Member
|
|
Join Date: Feb 2018
Posts: 12
|
|
|
Re: How to display products with a particular attribute
Quote:
Originally Posted by tony_sologubov
I feel there is a problem with decorated version of \XLite\Model\Repo\Product class. It should be as follows:
PHP Code:
<?php
namespace XLite\Module\Astur\SirtoliSkin\Model\Repo;
abstract class Product extends \XLite\Model\Repo\Product implements \XLite\Base\IDecorator {
public function findAllVintage() {
$name = 'Vintage';
$value = 'Yes';
$result = \XLite\Core\Database::getRepo('\XLite\Model\AttributeValue\AttributeValueSelect')
->createQueryBuilder('avs')
->linkInner('avs.attribute', 'a')
->linkInner('a.translations', 'at')
->linkInner('avs.attribute_option', 'ao')
->linkInner('ao.translations', 'aot')
->andWhere('at.name = :attributename AND aot.name = :optionvalue')
->setParameter('attributename', $name)
->setParameter('optionvalue', $value)
->getResult();
$return = array();
foreach ($result as $attribute) {
$return[] = $attribute->getProduct();
}
return $return;
}
}
instead of yours:
PHP Code:
<?php
namespace XLite\Module\Astur\SirtoliSkin\Model\Repo;
class Product extends \XLite\Model\Repo\Product implements \XLite\Base\IDecorator {
protected $name = 'Vintage';
protected $value = 'Yes';
public function findAllVintage() {
return \XLite\Core\Database::getRepo('\XLite\Model\AttributeValue\AttributeValueSelect')
->createQueryBuilder('avs')
->linkInner('avs.attribute', 'a')
->linkInner('a.translations', 'at')
->linkInner('avs.attribute_option', 'ao')
->linkInner('ao.translations', 'aot')
->andWhere('at.name = :attributename AND aot.name = :optionvalue')
->setParameter('attributename', $name)
->setParameter('optionvalue', $value)
->getResult();
}
}
As you can see, there are couple of changes:
1) I foreach $result and call getProduct() of each $attribute returned from the database. If you do not do this, your findAllVintage() method will return AttributeValue objects instead of products.
2) I moved constants $name and $value into a method instead of them being a part of class properties.
Please, try my code and let me know if it works for you. If it does not, please give me a snapshot of how you set up a vintage attribute for a product.
|
Suppose i need attribute value of current product.
How can i add condition here ? Please advise.
__________________
xcart 4.7
|
|