/** * Internal helper function to remove all article variants for the deselected options. * @param \Shopware\Models\Article\Article $article * @param array $selectedOptions * */ protected function deleteVariantsForAllDeactivatedOptions($article, $selectedOptions) { $configuratorSet = $article->getConfiguratorSet(); $oldOptions = $configuratorSet->getOptions(); $ids = array(); /**@var $oldOption \Shopware\Models\Article\Configurator\Option*/ foreach ($oldOptions as $oldOption) { if (!array_key_exists($oldOption->getId(), $selectedOptions)) { $details = $this->getRepository()->getArticleDetailByConfiguratorOptionIdQuery($article->getId(), $oldOption->getId())->setHydrationMode(\Doctrine\ORM\AbstractQuery::HYDRATE_OBJECT)->getResult(); if (!empty($details)) { /**@var $detail \Shopware\Models\Article\Detail*/ foreach ($details as $detail) { if ($detail->getKind() === 1) { $article->setMainDetail(null); } $ids[] = $detail->getId(); Shopware()->Models()->remove($detail); } Shopware()->Models()->flush(); } } } if (!empty($ids)) { $builder = Shopware()->Models()->createQueryBuilder(); $builder->delete('Shopware\\Models\\Attribute\\Article', 'attribute')->where('attribute.articleDetailId IN (:articleDetailIds)')->setParameters(array('articleDetailIds' => $ids))->getQuery()->execute(); } }
/** * {@inheritDoc} */ public function setMainDetail($mainDetail) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setMainDetail', array($mainDetail)); return parent::setMainDetail($mainDetail); }