Adds/removes chosen article to/from article comparison list

@param object $sProductId product id
@param double $dAmount    amount
@param array  $aSel       (default null)
@param bool   $blOverride allow override
@param bool   $blBundle   bundled
513198
public function toCompareList(
        $sProductId = null,
        $dAmount = null,
        $aSel = null,
        $blOverride = false,
        $blBundle = false
    ) {
        // only if enabled and not search engine..
        if ($this->getViewConfig()->getShowCompareList() && !\OxidEsales\Eshop\Core\Registry::getUtils()->isSearchEngine()) {
            // #657 special treatment if we want to put on comparelist
            $blAddCompare = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('addcompare');
            $blRemoveCompare = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('removecompare');
            $sProductId = $sProductId ? $sProductId : \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('aid');
            if (($blAddCompare || $blRemoveCompare) && $sProductId) {
                // toggle state in session array
                $aItems = \OxidEsales\Eshop\Core\Registry::getSession()->getVariable('aFiltcompproducts');
                if ($blAddCompare && !isset($aItems[$sProductId])) {
                    $aItems[$sProductId] = true;
                }

                if ($blRemoveCompare) {
                    unset($aItems[$sProductId]);
                }

                \OxidEsales\Eshop\Core\Registry::getSession()->setVariable('aFiltcompproducts', $aItems);
                $oParentView = $this->getParent();

                // #843C there was problem then field "blIsOnComparisonList" was not set to article object
                if (($oProduct = $oParentView->getViewProduct())) {
                    if (isset($aItems[$oProduct->getId()])) {
                        $oProduct->setOnComparisonList(true);
                    } else {
                        $oProduct->setOnComparisonList(false);
                    }
                }

                $aViewProds = $oParentView->getViewProductList();
                if (is_array($aViewProds) && count($aViewProds)) {
                    foreach ($aViewProds as $oProduct) {
                        if (isset($aItems[$oProduct->getId()])) {
                            $oProduct->setOnComparisonList(true);
                        } else {
                            $oProduct->setOnComparisonList(false);
                        }
                    }
                }
            }
        }
    }
1106179
@Override
	public void removeByCProductId(long CProductId) {
		for (CommerceWishListItem commerceWishListItem : findByCProductId(
				CProductId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
			remove(commerceWishListItem);
		}
	}
325499
public function delete($product_id)
    {
        $result = null;
        $this->hook->attach('product.compare.delete.before', $product_id, $result, $this);

        if (isset($result)) {
            return (bool) $result;
        }

        $compared = $this->getList();

        if (empty($compared)) {
            return false;
        }

        $product_ids = array_flip($compared);
        unset($product_ids[$product_id]);

        $result = $this->set(array_keys($product_ids));
        $this->hook->attach('product.compare.delete.after', $product_id, $result, $this);
        return (bool) $result;
    }
865220
public function AddArticle($sArticleId, $dAmount = 1, $sComment = null)
    {
        $dNewAmount = 0;
        $aItemData = array();
        $oItem = TdbPkgShopWishlistArticle::GetNewInstance();
        /** @var $oItem TdbPkgShopWishlistArticle */
        if ($oItem->LoadFromFields(array('pkg_shop_wishlist_id' => $this->id, 'shop_article_id' => $sArticleId))) {
            $aItemData = $oItem->sqlData;
            $aItemData['amount'] += $dAmount;
        } else {
            $aItemData['pkg_shop_wishlist_id'] = $this->id;
            $aItemData['shop_article_id'] = $sArticleId;
            $aItemData['amount'] = $dAmount;
            $aItemData['datecreated'] = date('Y-m-d H:i:s');
        }
        if (!is_null($sComment)) {
            $aItemData['comment'] = $oItem->LoadFromRow($aItemData);
        }
        $oItem->LoadFromRow($aItemData);
        $oItem->AllowEditByAll(true);
        $oItem->Save();
        $dNewAmount = $aItemData['amount'];

        return $dNewAmount;
    }
500959
public function deleteFromProductCompare($compare_action_model)
    {
        $product_id = $this->getSubmitted('product_id');
        $result = $compare_action_model->delete($product_id);

        if ($this->isAjax()) {
            $this->outputJson($result);
        }

        $this->controlDeleteProductCompare($result, $product_id);
        $this->redirect($result['redirect'], $result['message'], $result['severity']);
    }
273815
public function addArticle($sOXID, $sDesc)
    {
        $blAdd = false;
        if ($sOXID) {
            // We force reading from master to prevent issues with slow replications or open transactions (see ESDEV-3804 and ESDEV-3822).
            $database = \OxidEsales\Eshop\Core\DatabaseProvider::getMaster(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);

            if (!$database->getOne("select oxid from oxobject2list where oxobjectid=" . $database->quote($sOXID) . " and oxlistid=" . $database->quote($this->getId()))) {
                $sUid = \OxidEsales\Eshop\Core\Registry::getUtilsObject()->generateUID();
                $sQ = "insert into oxobject2list ( oxid, oxobjectid, oxlistid, oxdesc ) values ( '$sUid', " . $database->quote($sOXID) . ", " . $database->quote($this->getId()) . ", " . $database->quote($sDesc) . " )";
                $blAdd = $database->execute($sQ);
            }
        }

        return $blAdd;
    }
120467
public function remove()
    {
        //if user selected not to update modules, skipping all updates
        if (\OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("noButton")) {
            \OxidEsales\Eshop\Core\Registry::getSession()->setVariable("blSkipDeletedExtChecking", true);

            return;
        }

        $oModuleList = oxNew(\OxidEsales\Eshop\Core\Module\ModuleList::class);
        $oModuleList->cleanup();
    }
299615
private function addRecommendedProducts(
        &$productsToDisplayCounter,
        $limit,
        $maxPerChild,
        $recommendedProducts,
        &$productsToDisplay,
        &$product
    ) {
        $i = 0;

        foreach ($recommendedProducts as $product) {
            //check if still exists
            if ($product->getId() && $productsToDisplayCounter < $limit
                && $i <= $maxPerChild
                && $product->isSaleable()
                && !$product->getParentId()
            ) {
                //we have a product to display
                $productsToDisplay[$product->getId()] = $product;
                $i++;
                $productsToDisplayCounter++;
            }
        }
    }
976183
protected function _addToDisabledList($sModuleId)
    {
        $aDisabledModules = (array) \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('aDisabledModules');

        $aModules = array_merge($aDisabledModules, [$sModuleId]);
        $aModules = array_unique($aModules);

        $this->_saveToConfig('aDisabledModules', $aModules, 'arr');
    }
587337
public function loadRecommArticles($sRecommId, $sArticlesFilter = null)
    {
        $sSelect = $this->_getArticleSelect($sRecommId, $sArticlesFilter);
        $this->selectString($sSelect);
    }
875155
protected function _getItemKey($sProductId, $aSel = null, $aPersParam = null)
    {
        $aSel = ($aSel != null) ? $aSel : [0 => '0'];

        return md5($sProductId . '|' . serialize($aSel) . '|' . serialize($aPersParam));
    }
498683
function removeProductCategories( $ruleID = false )
    {
        if ( $ruleID === false )
            $ruleID = $this->ID;
        $ruleID =(int) $ruleID;
        $db = eZDB::instance();
        $db->query( "DELETE FROM ezvatrule_product_category WHERE vatrule_id = $ruleID" );
    }
16108
function removeNotNeededNodes(parentElements, newChildren, oldChildren) {
  let remaining = parentElements.childNodes.length;
  if (oldChildren.length !== remaining) {
    console.warn(
      "ZLIQ: Something other then ZLIQ has manipulated the children of the element",
      parentElements,
      ". This can lead to sideffects. Consider using the 'isolated' attribute for this element to prevent updates."
    );
  }

  for (; remaining > newChildren.length; remaining--) {
    let childToRemove = parentElements.childNodes[remaining - 1];
    parentElements.removeChild(childToRemove);

    if (oldChildren.length < remaining) {
      continue;
    } else {
      let { cycle } = oldChildren[remaining - 1];

      triggerLifecycle(childToRemove, { cycle }, "removed");
    }
  }
}
557803
public function AddArticleIdToNoticeList($iArticleId, $iAmount = 1)
    {
        $dNewAmountOnList = 0;

        if (is_null($this->aNoticeList)) {
            $this->GetNoticeListArticles();
        }
        // check if the item being pushed is already in the end of the queue
        $iMaxQueueLength = 1000;

        $queNotEmpty = (count($this->aNoticeList) > 0);

        if (array_key_exists($iArticleId, $this->aNoticeList)) {
            // we do not allow placing an article more than once on the notice list
            $dNewAmountOnList = false;
        } else {
            $oNoticeListItem = TdbShopUserNoticeList::GetNewInstance();
            /** @var $oNoticeListItem TdbShopUserNoticeList */
            $aData = array('shop_article_id' => $iArticleId, 'date_added' => date('Y-m-d H:i:s'), 'data_extranet_user_id' => $this->id, 'amount' => $iAmount);
            $oNoticeListItem->LoadFromRow($aData);
            if (!is_null($this->id) && $this->IsLoggedIn()) {
                $oNoticeListItem->Save();
            }
            $this->aNoticeList[$oNoticeListItem->fieldShopArticleId] = $oNoticeListItem->sqlData;
        }

        if (false !== $dNewAmountOnList) {
            // remove item if amount drops to zero
            if ($this->aNoticeList[$iArticleId]['amount'] <= 0) {
                unset($this->aNoticeList[$iArticleId]);
            } else {
                $dNewAmountOnList = $this->aNoticeList[$iArticleId]['amount'];
            }

            // if the list is full, remove last item
            if (count($this->aNoticeList) > $iMaxQueueLength) {
                array_pop($this->aNoticeList);
            }

            // save list to cookie for users not signed in
            if (!$this->IsLoggedIn()) {
                $this->CommitNoticeListToCookie();
            }
        }

        return $dNewAmountOnList;
    }
722280
public function &GetFieldShopArticleVariantsList($aSelectedTypeValues = array(), $bLoadOnlyActive = true)
    {
        $sKey = 'oFieldShopArticleVariantsList'.serialize($aSelectedTypeValues);
        if ($bLoadOnlyActive) {
            $sKey .= 'active';
        } else {
            $sKey .= 'inactive';
        }
        $oVariantList = &$this->GetFromInternalCache($sKey);
        if (is_null($oVariantList)) {
            if (count($aSelectedTypeValues) > 0) {
                $query = "SELECT `shop_article`.*
                      FROM `shop_article`
                 LEFT JOIN `shop_article_shop_variant_type_value_mlt` ON `shop_article`.`id` = `shop_article_shop_variant_type_value_mlt`.`source_id`
                 LEFT JOIN `shop_variant_type_value` ON `shop_article_shop_variant_type_value_mlt`.`target_id` = `shop_variant_type_value`.`id`
                     WHERE `shop_article`.`variant_parent_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($this->id)."'
                   ";
                $aRestriction = array();
                foreach ($aSelectedTypeValues as $sShopVariantTypeId => $sShopVariantTypeValueId) {
                    $aRestriction[] = "(`shop_variant_type_value`.`shop_variant_type_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($sShopVariantTypeId)."' AND `shop_variant_type_value`.`id` = '".MySqlLegacySupport::getInstance()->real_escape_string($sShopVariantTypeValueId)."')";
                }
                $query .= ' AND ('.implode(' OR ', $aRestriction).')';

                if ($bLoadOnlyActive) {
                    $sActiveArticleRestriction = TdbShopArticleList::GetActiveArticleQueryRestriction(false);
                    if (!empty($sActiveArticleRestriction)) {
                        $query .= ' AND ('.$sActiveArticleRestriction.')';
                    }
                }
                $query .= ' GROUP BY `shop_article`.`id` HAVING COUNT(`shop_article`.`id`) = '.count($aSelectedTypeValues);
                $oVariantList = TdbShopArticleList::GetList($query);
            } else {
                $query = "SELECT `shop_article`.*
                      FROM `shop_article`
                     WHERE `shop_article`.`variant_parent_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($this->id)."'
                   ";
                if ($bLoadOnlyActive) {
                    $sActiveArticleRestriction = TdbShopArticleList::GetActiveArticleQueryRestriction(false);
                    if (!empty($sActiveArticleRestriction)) {
                        $query .= ' AND ('.$sActiveArticleRestriction.')';
                    }
                }
                $oVariantList = TdbShopArticleList::GetList($query);
            }

            $oVariantList->bAllowItemCache = true;
            $this->SetInternalCache($sKey, $oVariantList);
        }
        $oVariantList->GoToStart();

        return $oVariantList;
    }
955194
@Override
	public void removeByCProductId(long CProductId) {
		for (CommerceOrderItem commerceOrderItem : findByCProductId(
				CProductId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
			remove(commerceOrderItem);
		}
	}
73510
function addToBasket( $objectID, $optionList, $quantity )
    {
        $object = eZContentObject::fetch( $objectID );
        $nodeID = $object->attribute( 'main_node_id' );
        $price = 0.0;
        $isVATIncluded = true;
        $attributes = $object->contentObjectAttributes();

        $priceFound = false;

        foreach ( $attributes as $attribute )
        {
            $dataType = $attribute->dataType();
            if ( eZShopFunctions::isProductDatatype( $dataType->isA() ) )
            {
                $priceObj = $attribute->content();
                $price += $priceObj->attribute( 'price' );
                $priceFound = true;
            }
        }

        if ( !$priceFound )
        {
            eZDebug::writeError( 'Attempted to add object without price to basket.' );
            return array( 'status' => eZModuleOperationInfo::STATUS_CANCELLED );
        }

        $currency = $priceObj->attribute( 'currency' );

        // Check for 'option sets' in option list.
        // If found each 'option set' will be added as a separate product purchase.
        $hasOptionSet = false;
        foreach ( array_keys( $optionList ) as $optionKey )
        {
            if ( substr( $optionKey, 0, 4 ) == 'set_' )
            {
                $returnStatus = eZShopOperationCollection::addToBasket( $objectID, $optionList[$optionKey] );
                // If adding one 'option set' fails we should stop immediately
                if ( $returnStatus['status'] == eZModuleOperationInfo::STATUS_CANCELLED )
                    return $returnStatus;
                $hasOptionSet = true;
            }
        }
        if ( $hasOptionSet )
            return $returnStatus;


        $unvalidatedAttributes = array();
        foreach ( $attributes as $attribute )
        {
            $dataType = $attribute->dataType();

            if ( $dataType->isAddToBasketValidationRequired() )
            {
                $errors = array();
                if ( $attribute->validateAddToBasket( $optionList[$attribute->attribute('id')], $errors ) !== eZInputValidator::STATE_ACCEPTED )
                {
                    $description = $errors;
                    $contentClassAttribute = $attribute->contentClassAttribute();
                    $attributeName = $contentClassAttribute->attribute( 'name' );
                    $unvalidatedAttributes[] = array( "name" => $attributeName,
                                                      "description" => $description );
                }
            }
        }
        if ( count( $unvalidatedAttributes ) > 0 )
        {
            return array( 'status' => eZModuleOperationInfo::STATUS_CANCELLED,
                          'reason' => 'validation',
                          'error_data' => $unvalidatedAttributes );
        }

        $basket = eZBasket::currentBasket();

        /* Check if the item with the same options is not already in the basket: */
        $itemID = false;
        $collection = $basket->attribute( 'productcollection' );
        if ( !$collection )
        {
            eZDebug::writeError( 'Unable to find product collection.' );
            return array( 'status' => eZModuleOperationInfo::STATUS_CANCELLED );
        }
        else
        {
            $collection->setAttribute( 'currency_code', $currency );
            $collection->store();

            $count = 0;
            /* Calculate number of options passed via the HTTP variable: */
            foreach ( array_keys( $optionList ) as $key )
            {
                if ( is_array( $optionList[$key] ) )
                    $count += count( $optionList[$key] );
                else
                    $count++;
            }
            $collectionItems = $collection->itemList( false );
            foreach ( $collectionItems as $item )
            {
                /* For all items in the basket which have the same object_id: */
                if ( $item['contentobject_id'] == $objectID )
                {
                    $options = eZProductCollectionItemOption::fetchList( $item['id'], false );
                    /* If the number of option for this item is not the same as in the HTTP variable: */
                    if ( count( $options ) != $count )
                    {
                        break;
                    }
                    $theSame = true;
                    foreach ( $options as $option )
                    {
                        /* If any option differs, go away: */
                        if ( ( is_array( $optionList[$option['object_attribute_id']] ) &&
                               !in_array( $option['option_item_id'], $optionList[$option['object_attribute_id']] ) )
                             || ( !is_array( $optionList[$option['object_attribute_id']] ) &&
                                  $option['option_item_id'] != $optionList[$option['object_attribute_id']] ) )
                        {
                            $theSame = false;
                            break;
                        }
                    }
                    if ( $theSame )
                    {
                        $itemID = $item['id'];
                        break;
                    }
                }
            }

            if ( $itemID )
            {
                /* If found in the basket, just increment number of that items: */
                $item = eZProductCollectionItem::fetch( $itemID );
                $item->setAttribute( 'item_count', $quantity + $item->attribute( 'item_count' ) );
                $item->store();
            }
            else
            {
                $item = eZProductCollectionItem::create( $basket->attribute( "productcollection_id" ) );

                $item->setAttribute( 'name', $object->attribute( 'name' ) );
                $item->setAttribute( "contentobject_id", $objectID );
                $item->setAttribute( "item_count", $quantity );
                $item->setAttribute( "price", $price );
                if ( $priceObj->attribute( 'is_vat_included' ) )
                {
                    $item->setAttribute( "is_vat_inc", '1' );
                }
                else
                {
                    $item->setAttribute( "is_vat_inc", '0' );
                }
                $item->setAttribute( "vat_value", $priceObj->attribute( 'vat_percent' ) );
                $item->setAttribute( "discount", $priceObj->attribute( 'discount_percent' ) );
                $item->store();
                $priceWithoutOptions = $price;

                $optionIDList = array();
                foreach ( array_keys( $optionList ) as $key )
                {
                    $attributeID = $key;
                    $optionString = $optionList[$key];
                    if ( is_array( $optionString ) )
                    {
                        foreach ( $optionString as $optionID )
                        {
                            $optionIDList[] = array( 'attribute_id' => $attributeID,
                                                     'option_string' => $optionID );
                        }
                    }
                    else
                    {
                        $optionIDList[] = array( 'attribute_id' => $attributeID,
                                                 'option_string' => $optionString );
                    }
                }

                $db = eZDB::instance();
                $db->begin();
                foreach ( $optionIDList as $optionIDItem )
                {
                    $attributeID = $optionIDItem['attribute_id'];
                    $optionString = $optionIDItem['option_string'];

                    $attribute = eZContentObjectAttribute::fetch( $attributeID, $object->attribute( 'current_version' ) );
                    $dataType = $attribute->dataType();
                    $optionData = $dataType->productOptionInformation( $attribute, $optionString, $item );
                    if ( $optionData )
                    {
                        $optionData['additional_price'] = eZShopFunctions::convertAdditionalPrice( $currency, $optionData['additional_price'] );
                        $optionItem = eZProductCollectionItemOption::create( $item->attribute( 'id' ), $optionData['id'], $optionData['name'],
                                                                             $optionData['value'], $optionData['additional_price'], $attributeID );
                        $optionItem->store();
                        $price += $optionData['additional_price'];
                    }
                }

                if ( $price != $priceWithoutOptions )
                {
                    $item->setAttribute( "price", $price );
                    $item->store();
                }
                $db->commit();
            }
        }

        return array( 'status' => eZModuleOperationInfo::STATUS_CONTINUE );
    }