Properties of selections
Posted: 26 Jan 2017, 12:03
Hi,
I tried to adapt the behaviour of the displayed properties for selections. The idea is to show only the properties of the selected variant as the attributes are done.
Here is the code snipplet of Standard.php of the catalog detail:
And the init section of the partial body-default.php:
With this code $propMap seems to stay empty. Could the $domains array be the problem, there is not product/property domain listed? I tried it with the additional domain 'product/property' with no success. Any suggestions?
Regards
Simon
I tried to adapt the behaviour of the displayed properties for selections. The idea is to show only the properties of the selected variant as the attributes are done.
Here is the code snipplet of Standard.php of the catalog detail:
Code: Select all
...
$context = $this->getContext();
$prodid = $view->param( 'd_prodid' );
$domains = array( 'media', 'price', 'text', 'attribute', 'product' );
$controller = \Aimeos\Controller\Frontend\Factory::createController( $context, 'catalog' );
$productItem = $this->getProductItem( $prodid, $domains );
$this->addMetaItems( $productItem, $this->expire, $this->tags );
$productManager = $controller->createManager( 'product' );
$productIds = array_keys( $productItem->getRefItems( 'product' ) );
$products = $this->getDomainItems( $productManager, 'product.id', $productIds, $domains );
$attrIds = array_keys( $productItem->getRefItems( 'attribute' ) );
$mediaIds = array_keys( $productItem->getRefItems( 'media' ) );
$propIds = array_keys( $productItem->getRefItems( 'product/property' ) );
foreach( $products as $product )
{
$attrIds = array_merge( $attrIds, array_keys( $product->getRefItems( 'attribute' ) ) );
$mediaIds = array_merge( $mediaIds, array_keys( $product->getRefItems( 'media' ) ) );
$propIds = array_merge( $propIds, array_keys( $product->getRefItems( 'product/property' ) ) );
}
$attributeManager = $controller->createManager( 'attribute' );
$attributeItems = $this->getDomainItems( $attributeManager, 'attribute.id', $attrIds, $domains );
$this->addMetaItems( $attributeItems, $this->expire, $this->tags );
$mediaManager = $controller->createManager( 'media' );
$mediaItems = $this->getDomainItems( $mediaManager, 'media.id', $mediaIds, $domains );
$this->addMetaItems( $mediaItems, $this->expire, $this->tags );
$propertyManager = $controller->createManager( 'product/property' );
$propertyItems = $this->getDomainItems( $propertyManager, 'product.property.id', $propIds, $domains );
$this->addMetaItems( $propertyItems, $this->expire, $this->tags );
...
Code: Select all
...
$attrMap = $subAttrDeps = array();
$attrItems = $this->get( 'detailAttributeItems', array() );
$propMap = $subPropDeps = array();
$propItems = $this->get( 'detailPropertyItems', array() );
foreach( $this->get( 'detailProductItems', array() ) as $subProdId => $subProduct )
{
$subItems = $subProduct->getRefItems( 'attribute', null, 'default' );
$subItems += $subProduct->getRefItems( 'attribute', null, 'variant' ); // show product variant attributes as well
foreach( $subItems as $attrId => $attrItem )
{
if( isset( $attrItems[ $attrId ] ) )
{
$attrMap[ $attrItem->getType() ][ $attrId ] = $attrItems[ $attrId ];
$subAttrDeps[ $attrId ][] = $subProdId;
}
}
$subItems = $subProduct->getRefItems( 'product/property' );
foreach( $subItems as $propId => $propItem )
{
if( isset( $propItems[ $propId ] ) )
{
$propMap[ $propItem->getType() ][ $propId ] = $propItems[ $propId ];
$subPropDeps[ $propId ][] = $subProdId;
}
}
}
ksort( $attrMap );
ksort( $propMap );
...
Regards
Simon