Create a new review for given article with given data.

@param array          $aUserData
@param TdbShopArticle $oArticle

@return TdbShopArticleReview
779485
protected function CreateReview($aUserData, $oArticle)
    {
        $oModuleConfiguration = $this->GetModuleConfiguration();
        $oReviewItem = TdbShopArticleReview::GetNewInstance(); /*@var $oReviewItem TdbShopArticleReview*/
        $aUserData['shop_article_id'] = $oArticle->id;
        $oReviewItem->LoadFromRowProtected($aUserData);
        if ($oModuleConfiguration->fieldManageReviews) {
            $oReviewItem->sqlData['publish'] = '0';
        } else {
            $oReviewItem->sqlData['publish'] = '1';
        }
        $oReviewItem->AllowEditByAll(true);
        $oReviewItem->Save();

        return $oReviewItem;
    }
894000
protected function GetVariantInfo($oArticle, $aData)
    {
        $aVariantTypeList = array();
        if ($oArticle) {
            if ($oArticle->IsVariant()) {
                $oVariantSet = $oArticle->GetFieldShopVariantSet();
                $oVariantTypes = $oVariantSet->GetFieldShopVariantTypeList();
                while ($oVariantType = $oVariantTypes->Next()) {
                    $oValue = $oArticle->GetActiveVariantValue($oVariantType->fieldIdentifier);
                    $aType = array(
                        'sTitle' => $oVariantType->fieldName,
                        'sSystemName' => $oVariantType->fieldIdentifier,
                        'cms_media_id' => $oVariantType->fieldCmsMediaId,
                        'aItems' => array(),
                    );
                    $aItems = array();
                    $aItem = array(
                        'sTitle' => $oValue->fieldName,
                        'sColor' => $oValue->fieldColorCode,
                        'cms_media_id' => $oValue->fieldCmsMediaId,
                        'bIsActive' => false,
                        'sSelectLink' => '',
                    );
                    $aItems[] = $aItem;
                    $aType['aItems'] = $aItems;
                    $aVariantTypeList[] = $aType;
                }
            }
            $aData['aVariantTypes'] = $aVariantTypeList;
        }

        return $aData;
    }
451597
public function getArticles($iStart = null, $iNrofArticles = null, $blReload = false)
    {
        // cached ?
        if ($this->_oArticles !== null && !$blReload) {
            return $this->_oArticles;
        }

        $this->_oArticles = oxNew(\OxidEsales\Eshop\Application\Model\ArticleList::class);

        if ($iStart !== null && $iNrofArticles !== null) {
            $this->_oArticles->setSqlLimit($iStart, $iNrofArticles);
        }

        // loading basket items
        $this->_oArticles->loadRecommArticles($this->getId(), $this->_sArticlesFilter);

        return $this->_oArticles;
    }
29895
protected function UpdateArticleReviewStats($iArticleId)
    {
        $oArticle = TdbShopArticle::GetNewInstance();
        /** @var $oArticle TdbShopArticle */
        if ($oArticle->Load($iArticleId)) {
            $oArticle->UpdateStatsReviews();
        }
    }
693465
public function &GetArticleObject()
    {
        if (is_null($this->oArticle)) {
            $this->oArticle = TdbShopArticle::GetNewInstance();
            if (!$this->oArticle->Load($this->sqlData['shop_article_id'])) {
                $this->oArticle = null;
            }
        }

        return $this->oArticle;
    }
741151
protected function GetReviewsForUser()
    {
        $oUserReviews = null;
        $oUser = TdbDataExtranetUser::GetInstance();
        if ($oUser->IsLoggedIn()) {
            $oUserReviews = $oUser->GetFieldShopArticleReviewList();
        }

        return $oUserReviews;
    }
751987
protected function ValidateWriteReviewData($aUserData)
    {
        $bDataValid = false;
        $oMsgManager = TCMSMessageManager::GetInstance();
        if (is_array($aUserData)) {
            $bDataValid = true;
            $sCaptcha = '';
            if ($this->NeedCaptcha()) {
                if (array_key_exists('captcha', $aUserData)) {
                    $sCaptcha = trim($aUserData['captcha']);
                }
                if (empty($sCaptcha) || $sCaptcha != $this->GetCaptchaValue()) {
                    $bDataValid = false;
                    $oMsgManager->AddMessage(TdbShopArticleReview::MSG_CONSUMER_BASE_NAME.'-captcha', 'INPUT-ERROR-INVALID-CAPTCHA');
                }
            }
            $aRequiredFields = $this->GetRequiredFields();
            foreach ($aRequiredFields as $sFieldName) {
                $sVal = '';
                if (array_key_exists($sFieldName, $aUserData)) {
                    $sVal = trim($aUserData[$sFieldName]);
                }
                if (empty($sVal)) {
                    $bDataValid = false;
                    $oMsgManager->AddMessage(TdbShopArticleReview::MSG_CONSUMER_BASE_NAME.'-'.$sFieldName, 'ERROR-USER-REQUIRED-FIELD-MISSING');
                }
            }

            if ($this->InsertOfReviewLocked()) {
                $bDataValid = false;
                $oMsgManager->AddMessage(MTPkgShopArticleReview::MSG_CONSUMER_NAME, 'ERROR-REVIEW-IS-LOCKED');
            }
        }

        return $bDataValid;
    }
917726
public function ArticleAffected(TShopBasketArticle &$oArticle)
    {
        $shopShippingTypeDataAccess = $this->getShopShippingTypeDataAccess();
        $bAffected = false;
        $oArticleShippingType = &$oArticle->GetActingShippingType();
        // if the article is already marked with this shipping type, then we keep it
        if (!is_null($oArticleShippingType) && $oArticleShippingType->id == $this->id) {
            $bAffected = true;
        } elseif (is_null($oArticleShippingType)) {
            // article has no shipping type yet...
            // check article groups
            $bArticleGroupValid = false;
            $aGroupRestriction = $shopShippingTypeDataAccess->getPermittedArticleGroupIds($this->id);
            if (!is_array($aGroupRestriction) || count($aGroupRestriction) < 1) {
                $bArticleGroupValid = true;
            } else {
                $bArticleGroupValid = $oArticle->IsInArticleGroups($aGroupRestriction);
            }

            // check product categories
            $bArticleCategoryValid = false;
            if ($bArticleGroupValid) {
                $aCategoryRestriction = $shopShippingTypeDataAccess->getPermittedCategoryIds($this->id);
                if (!is_array($aCategoryRestriction) || count($aCategoryRestriction) < 1) {
                    $bArticleCategoryValid = true;
                } else {
                    $bArticleCategoryValid = $oArticle->IsInCategory($aCategoryRestriction);
                }
            }

            // check articles
            $bArticleValid = false;
            if ($bArticleGroupValid && $bArticleCategoryValid) {
                $aArticleRestriction = $shopShippingTypeDataAccess->getPermittedArticleIds($this->id);
                if (!is_array($aArticleRestriction) || count($aArticleRestriction) < 1) {
                    $bArticleValid = true;
                } else {
                    if (in_array($oArticle->id, $aArticleRestriction)) {
                        $bArticleValid = true;
                    }
                }
            }

            $bAffected = ($bArticleGroupValid && $bArticleCategoryValid && $bArticleValid);
        }

        return $bAffected;
    }
721615
public function &GetArticlesAffectedByShippingType(TdbShopShippingType &$oShippingType)
    {
        $oArticles = new TShopBasketArticleList();
        /** @var $oArticles TShopBasketArticleList */
        $iPointer = $this->getItemPointer();
        $this->GoToStart();
        while ($oItem = &$this->Next()) {
            if ($oShippingType->ArticleAffected($oItem)) {
                $oArticles->AddItem($oItem);
            }
        }
        if ($oArticles->Length() > 0 && $oShippingType->fieldApplyToAllProducts) {
            // this shipping type should match ALL articles... so we now work with all articles
            $this->GoToStart();
            $oArticles = new TShopBasketArticleList();
            /** @var $oArticles TShopBasketArticleList */
            while ($oItem = &$this->Next()) {
                $oArticles->AddItem($oItem);
            }
        }
        // if at least some items matched, we now need to check if the sume of the items matches the shipping type requirement
        if ($oShippingType->ArticleListValidForShippingType($oArticles)) {
            // we keep the list. we now need to mark all items in the list with that shipping type
            $oArticles->GoToStart();
            while ($oItem = &$oArticles->Next()) {
                $this->SetShippingTypeForArticle($oItem, $oShippingType);
            }
            $oArticles->GoToStart();
        } else {
            // does not match... so reset the list
            $oArticles = new TShopBasketArticleList();
            /** @var $oArticles TShopBasketArticleList */
        }

        $this->setItemPointer($iPointer);

        return $oArticles;
    }
831160
public function isForBundleItem($oArticle)
    {
        if ($this->oxdiscount__oxaddsumtype->value != 'itm') {
            return false;
        }

        $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
        $sQ = "select 1 from oxobject2discount where oxdiscountid=" . $oDb->quote($this->getId());
        $sQ .= $this->_getProductCheckQuery($oArticle);
        if (!($blOk = (bool) $oDb->getOne($sQ))) {
            // additional checks for amounts and other dependencies
            $blOk = $this->_checkForArticleCategories($oArticle);
        }

        return $blOk;
    }
725812
public ArticleAttachments createUploadArticle(long articleId, File file) throws IOException {
        return createUploadArticle(articleId, file, false);
  }
169946
protected function LoadFromBasketPostProcessData($oBasket, &$aOrderData)
    {
        parent::LoadFromBasketPostProcessData($oBasket, $aOrderData);
        $oUser = TdbDataExtranetUser::GetInstance();
        $oShipping = $oUser->GetShippingAddress();
        $aOrderData['adr_shipping_is_dhl_packstation'] = $oShipping->fieldIsDhlPackstation;
    }
432998
protected function ValidateUser($aUserData)
    {
        $bValid = false;
        $oActiveUser = self::getExtranetUserProvider()->getActiveUser();
        if ($oActiveUser && is_array($oActiveUser->sqlData) && array_key_exists('customer_number', $oActiveUser->sqlData)) {
            $aUserData['customer_number'] = $oActiveUser->sqlData['customer_number'];
        }
        $oUser = TdbDataExtranetUser::GetNewInstance($aUserData);

        $bValid = $oUser->ValidateData();

        if ('register' == TShopStepUserDataV2::GetUserMode()) {
            $bValid = ($oUser->ValidateLoginData($aUserData) && $bValid);
        } elseif ('guest' == TShopStepUserDataV2::GetUserMode()) {
            if (TdbDataExtranet::GetInstance()->fieldLoginIsEmail) {
                $bValid = ($this->validateUserEMail($aUserData['name']) && $bValid);
            } else {
                $bValid = ($this->validateUserEMail($aUserData['email']) && $bValid);
            }
        }

        return $bValid;
    }
1019792
public function SendMail($oArticle = null, $sEmail = '')
    {
        // ------------------------------------------------------------------------
        static $aPortals = array();
        if (null === $oArticle) {
            $oArticle = $this->GetFieldShopArticle();
        }
        if ('' === $sEmail) {
            $sEmail = $this->fieldPreorderUserEmail;
        }
        if (!is_null($oArticle) && !empty($sEmail)) {
            $oMail = TdbDataMailProfile::GetProfile('preorder-available');
            $sArticleDetailLink = $oArticle->GetDetailLink(true);

            if (!array_key_exists($this->fieldCmsPortalId, $aPortals)) {
                $oCMSPortal = TdbCmsPortal::GetNewInstance();
                if ($oCMSPortal->Load($this->fieldCmsPortalId)) {
                    $aPortals[$this->fieldCmsPortalId] = $oCMSPortal;
                }
            }

            $sArticleBasketLink = '';
            if (array_key_exists($this->fieldCmsPortalId, $aPortals)) {
                $sArticleBasketLink = 'http://'.$aPortals[$this->fieldCmsPortalId]->GetPrimaryDomain().'/'.TdbShopArticle::URL_EXTERNAL_TO_BASKET_REQUEST.'/id/'.urlencode($oArticle->id);
            }

            $oMail->AddData('sUserEmail', $sEmail);
            $oMail->AddData('sArticleName', $oArticle->GetName());
            $oMail->AddData('sArticleDetailLink', $sArticleDetailLink);
            $oMail->AddData('sArticleBasketLink', $sArticleBasketLink);

            $oMail->ChangeToAddress($sEmail);
            $oMail->SendUsingObjectView('emails', 'Customer');

            $this->AllowEditByAll(true);
            $this->Delete();
            $this->AllowEditByAll(false);

            return true;
        } else {
            return false;
        }
    }
16375
protected function renderArticle(Request $request, ArticleInterface $object, $view, $pageNumber, $attributes = [])
    {
        $object = $this->normalizeArticle($object);

        $requestFormat = $request->getRequestFormat();
        $viewTemplate = $view . '.' . $requestFormat . '.twig';

        $content = $this->serializeArticle($object, $pageNumber);

        try {
            return $this->render(
                $viewTemplate,
                $this->get('sulu_website.resolver.template_attribute')->resolve(array_merge($content, $attributes)),
                $this->createResponse($request)
            );
        } catch (\InvalidArgumentException $exception) {
            // template not found
            throw new HttpException(406, 'Error encountered when rendering content', $exception);
        }
    }
337333
public function setActionArticle()
    {
        $sArticleId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('oxarticleid');
        $sActionId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('oxid');
        $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();

        $oDb->Execute(
            'delete from oxobject2action '
            . 'where oxactionid=' . $oDb->quote($sActionId)
            . ' and oxclass = "oxarticle"'
        );

        $oObject2Promotion = oxNew(\OxidEsales\Eshop\Core\Model\BaseModel::class);
        $oObject2Promotion->init('oxobject2action');
        $oObject2Promotion->oxobject2action__oxactionid = new \OxidEsales\Eshop\Core\Field($sActionId);
        $oObject2Promotion->oxobject2action__oxobjectid = new \OxidEsales\Eshop\Core\Field($sArticleId);
        $oObject2Promotion->oxobject2action__oxclass = new \OxidEsales\Eshop\Core\Field("oxarticle");
        $oObject2Promotion->save();
    }
606125
private function mapReviewAndRating($reviewAndRatingData)
    {
        $reviewAndRating = new ReviewAndRating();
        $reviewAndRating
            ->setReviewId($reviewAndRatingData['reviewId'])
            ->setRatingId($reviewAndRatingData['ratingId'])
            ->setRating($reviewAndRatingData['rating'])
            ->setReviewText($reviewAndRatingData['text'])
            ->setObjectId($reviewAndRatingData['objectId'])
            ->setObjectType($reviewAndRatingData['objectType'])
            ->setCreatedAt($reviewAndRatingData['createdAt']);

        return $reviewAndRating;
    }