/** @param $productsIDs array of product IDs to compare @param $compareBy array of attribute IDs to include in the result compare list */ function __construct($productsIDs, $compareBy) { $prodAttributes = array(); foreach ($productsIDs as $prodId) { $product = new Product($prodId); $prodAttributes[$product->id()] = $product->attributes(); $this->items[$product->id()] = array(); } foreach ($compareBy as $attrId) { foreach ($prodAttributes as $prodId => $attrs) { $attr = new Attribute($attrId); if ($this->isSetInAtLeastOne($prodAttributes, $attr->id())) { $this->items[$prodId][$attr->id()] = $attrs->get($attr->id()); $this->fullList[$attr->id()] = $attr; if (!$this->isEqualForAll($prodAttributes, $attr->id())) { $this->listOfDifferences[$attr->id()] = $attr; } } } } }
protected function add(Attribute $productAttr) { $optionAttr = new ProductOptionAttribute($productAttr->id(), $this->optionId); CategoryAttributes::add($optionAttr->isNull() ? $productAttr : $optionAttr); //override with option attribute it is not null }