View Single Post
  #2  
Old 12-11-2014, 05:41 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: How to display products with a particular attribute

This thread is about kind of what you need:
http://forum.x-cart.com/showthread.php?t=70512

Anyway, here is couple more things to consider:

1) If you want to pull products with attribute Color having value Red and these attributes are product-specific, you would call it like this:

PHP Code:
$name 'Color';
$value 'Red';

$products = \XLite\Core\Database::getRepo('\XLite\Model\Product')
    ->
createQueryBuilder('p')
    ->
linkInner('p.attributes')
    ->
linkInner('attributes.translations''atranslations')
    ->
linkInner('attributes.attribute_options')
    ->
linkInner('attribute_options.translations''aotranslations')
    ->
andWhere('atranslations.name = :name AND aotranslations.name = :value')
    ->
setParameter('name'$name)
    ->
setParameter('value'$value)
    ->
getResult();

foreach (
$products as $product) {
    echo 
$product->getName();


2) If you need the same but for global attributes you would call it like this:
PHP Code:
$name 'Manufacturer';
$value 'Toyty';

$a = \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();

foreach (
$a as $av) {
    echo 
$av->getProduct()->getName() . ' ';


Please, let me know if it helps.
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote