- Created new templates for user data management including address list, product list, and order forms. - Implemented responsive design for user panel breadcrumbs and address management. - Added pagination functionality for product listings. - Integrated Smarty template engine for dynamic content rendering. - Ensured compatibility with existing user data structures and configurations.
1694 lines
60 KiB
PHP
1694 lines
60 KiB
PHP
<?php
|
|
/**
|
|
* SOTESHOP/stUser
|
|
*
|
|
* Ten plik należy do aplikacji stUser opartej na licencji (Professional License SOTE).
|
|
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
|
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
|
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
|
*
|
|
* @package stUser
|
|
* @subpackage actions
|
|
* @copyright SOTE (www.sote.pl)
|
|
* @license http://www.sote.pl/license/sote (Professional License SOTE)
|
|
* @version $Id: actions.class.php 2671 2009-08-19 14:33:54Z bartek $
|
|
*/
|
|
|
|
use PhpParser\Node\Expr\Instanceof_;
|
|
|
|
/**
|
|
* Akcje profili użytkownika
|
|
*
|
|
* @author Bartosz Alejski <bartosz.alejski@sote.pl>
|
|
*
|
|
* @package stUser
|
|
* @subpackage actions
|
|
*/
|
|
class stUserDataActions extends stActions
|
|
{
|
|
|
|
public function executeCreateFirstUserData()
|
|
{
|
|
if($this->getUser()->isAuthenticated())
|
|
{
|
|
$this->smarty = new stSmarty($this->getModuleName());
|
|
|
|
$user_config = stConfig::getInstance(sfContext::getInstance(), 'stUser');
|
|
$this->show_region = $user_config->get('show_region');
|
|
$this->show_pesel = $user_config->get('show_pesel');
|
|
$this->show_address_more = $user_config->get('show_address_more');
|
|
|
|
$change_default_user = $user_config->get('change_default_user');
|
|
|
|
if ($this->getRequest()->getMethod() == sfRequest::POST)
|
|
{
|
|
$userDataBilling = $this->getRequestParameter('user_data_billing');
|
|
$userDataDelivery = $this->getRequestParameter('user_data_delivery');
|
|
|
|
stUser::updateUserData($userDataBilling['id'],$this->getUser()->getGuardUser()->getId(),1,1,$userDataBilling);
|
|
|
|
if($this->getRequestParameter('different_delivery'))
|
|
{
|
|
stUser::updateUserData($userDataDelivery['id'],$this->getUser()->getGuardUser()->getId(),0,1,$userDataDelivery);
|
|
}
|
|
else
|
|
{
|
|
stUser::updateUserData($userDataDelivery['id'],$this->getUser()->getGuardUser()->getId(),0,1,$userDataBilling);
|
|
}
|
|
|
|
if(!stTheme::is_responsive()){
|
|
$this->redirect('stUser/editAccount');
|
|
}else{
|
|
$this->redirect('stUserData/userPanel');
|
|
}
|
|
|
|
}
|
|
|
|
$userDataBilling = $this->getUserDataBillingDefault($this->getUser()->getGuardUser()->getId());
|
|
$this->userDataBilling = $userDataBilling;
|
|
|
|
$userDataDelivery = $this->getUserDataDeliveryDefault($this->getUser()->getGuardUser()->getId());
|
|
$this->userDataDelivery = $userDataDelivery;
|
|
|
|
$this->type1_delivery_checker = 1;
|
|
$this->type2_delivery_checker = 0;
|
|
|
|
if($change_default_user!=1)
|
|
{
|
|
$this->type1_billing_checker = 1;
|
|
$this->type2_billing_checker = 0;
|
|
}
|
|
else
|
|
{
|
|
$this->type1_billing_checker = 0;
|
|
$this->type2_billing_checker = 1;
|
|
}
|
|
|
|
$this->different_billing = 0;
|
|
|
|
}
|
|
else
|
|
{
|
|
stUser::processAuthentication();
|
|
}
|
|
}
|
|
|
|
public function executeCreateFirstUserDataBilling()
|
|
{
|
|
if($this->getUser()->isAuthenticated())
|
|
{
|
|
$userDataBilling = stUser::updateUserData(null,$this->getUser()->getGuardUser()->getId(),1,1);
|
|
$this->redirect('stUserData/editProfile?userDataType=billing&userDataId='.$userDataBilling->getId().'&showEditProfileForm=true');
|
|
}
|
|
else
|
|
{
|
|
stUser::processAuthentication();
|
|
}
|
|
}
|
|
|
|
public function executeCreateFirstUserDataDelivery()
|
|
{
|
|
if($this->getUser()->isAuthenticated())
|
|
{
|
|
$userDataDelivery = stUser::updateUserData(null,$this->getUser()->getGuardUser()->getId(),0,1);
|
|
$this->redirect('stUserData/editProfile?userDataType=delivery&userDataId='.$userDataDelivery->getId().'&showEditProfileForm=true');
|
|
|
|
}
|
|
else
|
|
{
|
|
stUser::processAuthentication();
|
|
}
|
|
}
|
|
|
|
|
|
public function getUserDataBillingDefault($user_id)
|
|
{
|
|
$c = new Criteria();
|
|
$c->add(UserDataPeer::SF_GUARD_USER_ID, $user_id);
|
|
$c->add(UserDataPeer::IS_DEFAULT , 1);
|
|
$c->add(UserDataPeer::IS_BILLING , 1);
|
|
if ($userDataBillingDefault = UserDataPeer::doSelectOne($c))
|
|
{
|
|
$this->user_data = $userDataBillingDefault;
|
|
}
|
|
else
|
|
{
|
|
$this->user_data = new UserData();
|
|
|
|
$this->user_data->setSfGuardUserId($user_id);
|
|
$this->user_data->setIsBilling(1);
|
|
$this->user_data->setIsDefault(1);
|
|
$this->user_data->setCountriesId(CountriesPeer::doSelectDefault(new Criteria())->getId());
|
|
}
|
|
|
|
$userDataBillingDefault = $this->user_data;
|
|
return $userDataBillingDefault;
|
|
}
|
|
|
|
public function getUserDataDeliveryDefault($user_id)
|
|
{
|
|
$c = new Criteria();
|
|
$c->add(UserDataPeer::SF_GUARD_USER_ID, $user_id);
|
|
$c->add(UserDataPeer::IS_DEFAULT , 1);
|
|
$c->add(UserDataPeer::IS_BILLING , 0);
|
|
if ($userDataDeliveryDefault = UserDataPeer::doSelectOne($c))
|
|
{
|
|
$this->user_data = $userDataDeliveryDefault;
|
|
}
|
|
else
|
|
{
|
|
$this->user_data = new UserData();
|
|
|
|
$this->user_data->setSfGuardUserId($user_id);
|
|
$this->user_data->setIsBilling(1);
|
|
$this->user_data->setIsDefault(1);
|
|
$this->user_data->setCountriesId(CountriesPeer::doSelectDefault(new Criteria())->getId());
|
|
}
|
|
|
|
$userDataDeliveryDefault = $this->user_data;
|
|
return $userDataDeliveryDefault;
|
|
}
|
|
|
|
public function getUserDataBillingAll($user_id)
|
|
{
|
|
$c = new Criteria();
|
|
$c->add(UserDataPeer::SF_GUARD_USER_ID, $user_id);
|
|
$c->add(UserDataPeer::IS_BILLING , 1);
|
|
$userDataBillingAll = UserDataPeer::doSelect($c);
|
|
|
|
return $userDataBillingAll;
|
|
}
|
|
|
|
public function getUserDataDeliveryAll($user_id)
|
|
{
|
|
$c = new Criteria();
|
|
$c->add(UserDataPeer::SF_GUARD_USER_ID, $user_id);
|
|
$c->add(UserDataPeer::IS_BILLING , 0);
|
|
$userDataDeliveryAll = UserDataPeer::doSelect($c);
|
|
|
|
return $userDataDeliveryAll;
|
|
}
|
|
|
|
public function executeUserPanel()
|
|
{
|
|
$this->smarty = new stSmarty($this->getModuleName());
|
|
|
|
if($this->getUser()->isAuthenticated())
|
|
{
|
|
|
|
$userDataBilling = $this->getUserDataBillingDefault($this->getUser()->getAttribute('user_id', null, 'sfGuardSecurityUser'));
|
|
$this->userDataBilling = $userDataBilling;
|
|
|
|
$userDataDelivery = $this->getUserDataDeliveryDefault($this->getUser()->getAttribute('user_id', null, 'sfGuardSecurityUser'));
|
|
$this->userDataDelivery = $userDataDelivery;
|
|
|
|
if(!stTheme::is_responsive()){
|
|
|
|
if($userDataBilling->getAddress()=="" || $userDataDelivery->getAddress()=="")
|
|
{
|
|
$this->redirect('stUserData/createFirstUserData');
|
|
}
|
|
|
|
}
|
|
|
|
$c = new Criteria();
|
|
$c->add(OrderPeer::SF_GUARD_USER_ID, $this->getUser()->getAttribute('user_id', null, 'sfGuardSecurityUser'));
|
|
$c->setLimit(10);
|
|
$orders = OrderPeer::doSelect($c);
|
|
|
|
if($orders)
|
|
{
|
|
$this->user_order = 1;
|
|
$this->orders = $orders;
|
|
}
|
|
|
|
$c = new Criteria();
|
|
$c->add(OrderPeer::SF_GUARD_USER_ID, $this->getUser()->getAttribute('user_id', null, 'sfGuardSecurityUser'));
|
|
$c->addDescendingOrderByColumn('CREATED_AT');
|
|
$lastOrder = OrderPeer::doSelectOne($c);
|
|
|
|
if($lastOrder)
|
|
{
|
|
$this->lastOrder = $lastOrder;
|
|
$this->currency = $lastOrder->getOrderCurrency();
|
|
|
|
$this->linkOrder = url_for('@stOrderListShowForUser?id=' . $lastOrder->getId() . '&hash_code=' . $lastOrder->getHashCode());
|
|
|
|
}
|
|
|
|
|
|
$c = new Criteria();
|
|
$c->add(DiscountUserPeer::SF_GUARD_USER_ID, $this->getUser()->getAttribute('user_id', null, 'sfGuardSecurityUser'));
|
|
$userDiscount = DiscountUserPeer::doSelectOne($c);
|
|
|
|
$uid = DiscountPeer::doSelectIdsByUser($this->getUser()->getGuardUser());
|
|
|
|
$c = new Criteria();
|
|
$c->add(DiscountPeer::ACTIVE, true);
|
|
|
|
if ($uid)
|
|
{
|
|
$uc = $c->getNewCriterion(DiscountPeer::ID, $uid, Criteria::IN);
|
|
$uc->addOr($c->getNewCriterion(DiscountPeer::ALL_CLIENTS, true));
|
|
$c->add($uc);
|
|
}
|
|
else
|
|
{
|
|
$c->add(DiscountPeer::ALL_CLIENTS, true);
|
|
}
|
|
|
|
$discount_count = DiscountPeer::doCount($c);
|
|
|
|
if($userDiscount){
|
|
$this->user_discounts = $discount_count > 0 || @$user_discount && $user_discount->getDiscount()->getValue() > 0;
|
|
}else{
|
|
$this->user_discounts = false;
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
stUser::processAuthentication();
|
|
}
|
|
|
|
$newsletterConfig = stConfig::getInstance($this->getContext(), 'stNewsletterBackend');
|
|
|
|
$newsletterConfig = $newsletterConfig->load();
|
|
|
|
$this->newsletterConfig = $newsletterConfig;
|
|
|
|
|
|
$pointsConfig = stConfig::getInstance($this->getContext(), 'stPointsBackend');
|
|
|
|
$pointsConfig = $pointsConfig->load();
|
|
|
|
stPoints::refreshLoginStatusPoints();
|
|
|
|
$this->pointsConfig = $pointsConfig;
|
|
|
|
}
|
|
|
|
public function executeTest()
|
|
{
|
|
$this->getUser()->setAuthenticated(false);
|
|
$this->redirect('stUserData/userPanel');
|
|
}
|
|
|
|
public function executeEditProfile()
|
|
{
|
|
$this->smarty = new stSmarty($this->getModuleName());
|
|
|
|
if($this->getUser()->isAuthenticated())
|
|
{
|
|
|
|
$userDataId = $this->getRequestParameter('userDataId');
|
|
$userData = $this->getRequestParameter('user_data');
|
|
$userDataType = $this->getRequestParameter('userDataType');
|
|
$showEditProfileForm = $this->getRequestParameter('showEditProfileForm');
|
|
$showMessage = $this->getRequestParameter('showMessage');
|
|
$this->isMyUserData($userDataId);
|
|
|
|
$showEditProfileForm = true;
|
|
|
|
$this->userDataId = $userDataId;
|
|
$this->userDataType = $userDataType;
|
|
$this->showMessage = $showMessage;
|
|
$this->showEditProfileForm = $showEditProfileForm;
|
|
|
|
}
|
|
else
|
|
{
|
|
stUser::processAuthentication();
|
|
}
|
|
}
|
|
|
|
public function executeSaveProfile()
|
|
{
|
|
if($this->getUser()->isAuthenticated())
|
|
{
|
|
|
|
$userDataId = $this->getRequestParameter('userDataId');
|
|
$userData = $this->getRequestParameter('user_data');
|
|
$userDataType = $this->getRequestParameter('userDataType');
|
|
$showEditProfileForm = $this->getRequestParameter('showEditProfileForm');
|
|
|
|
|
|
|
|
if($userDataType=="billing")
|
|
{
|
|
$isBilling = 1;
|
|
}
|
|
else
|
|
{
|
|
$isBilling = 0;
|
|
}
|
|
|
|
if($this->hasRequestParameter('user_data_delivery'))
|
|
{
|
|
$userData['country'] = $this->getRequestParameter('user_data_delivery[country]');
|
|
}
|
|
|
|
|
|
/* $c = new Criteria();
|
|
$c->add(UserDataPeer::SF_GUARD_USER_ID, $this->getUser()->getGuardUser()->getId());
|
|
$c->add(UserDataPeer::IS_BILLING, $isBilling);
|
|
|
|
if(!UserDataPeer::doSelectOne($c))
|
|
{
|
|
$userData['isDefault']=1;
|
|
}
|
|
|
|
|
|
if($userData['isDefault']==1){
|
|
$this->setDefaultUserData($userData['id'], $userData['isBilling']);
|
|
}*/
|
|
|
|
|
|
stUser::updateUserData($userData['id'],$this->getUser()->getGuardUser()->getId(),$userData['isBilling'],$userData['isDefault'],$userData);
|
|
|
|
if(!$showEditProfileForm)
|
|
{
|
|
$showEditProfileForm == false;
|
|
}
|
|
|
|
$this->userDataId = $userDataId;
|
|
$this->userDataType = $userDataType;
|
|
$this->showEditProfileForm = $showEditProfileForm;
|
|
|
|
$this->redirect('stUserData/addressList');
|
|
|
|
}
|
|
else
|
|
{
|
|
stUser::processAuthentication();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Usuwanie profilu
|
|
*/
|
|
public function executeCreateProfile()
|
|
{
|
|
|
|
if($this->getUser()->isAuthenticated())
|
|
{
|
|
$userDataType = $this->getRequestParameter('userDataType');
|
|
|
|
$userData = stUser::updateUserData('',$this->getUser()->getAttribute('user_id', null, 'sfGuardSecurityUser'),$this->getUserDataTypeNumericValue($userDataType),0);
|
|
|
|
$this->redirect('stUserData/editProfile?userDataType='.$userDataType.'&userDataId='.$userData->getId().'&showEditProfileForm=true');
|
|
}
|
|
else
|
|
{
|
|
stUser::processAuthentication();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Usuwanie profilu
|
|
*/
|
|
public function executeDeleteProfile()
|
|
{
|
|
if($this->getUser()->isAuthenticated())
|
|
{
|
|
|
|
$userDataType = $this->getRequestParameter('userDataType');
|
|
|
|
$c = new Criteria();
|
|
$c->add(UserDataPeer::ID, $this->getRequestParameter('userDataId'));
|
|
$c->add(UserDataPeer::SF_GUARD_USER_ID, $this->getUser()->getAttribute('user_id', null, 'sfGuardSecurityUser'));
|
|
UserDataPeer::doDelete($c);
|
|
|
|
if($this->getUserDataTypeNumericValue($userDataType)==1)
|
|
{
|
|
$userData = $this->getUserDataBillingDefault($this->getUser()->getAttribute('user_id', null, 'sfGuardSecurityUser'));
|
|
}
|
|
else
|
|
{
|
|
$userData = $this->getUserDataDeliveryDefault($this->getUser()->getAttribute('user_id', null, 'sfGuardSecurityUser'));
|
|
}
|
|
|
|
$this->redirect('stUserData/addressList');
|
|
|
|
}
|
|
else
|
|
{
|
|
stUser::processAuthentication();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
public function setDefaultUserData($userDataId, $isBilling)
|
|
{
|
|
if($this->getUser()->isAuthenticated())
|
|
{
|
|
|
|
$con = Propel::getConnection();
|
|
$c1 = new Criteria();
|
|
$c1->add(UserDataPeer::SF_GUARD_USER_ID , $this->getUser()->getAttribute('user_id', null, 'sfGuardSecurityUser'));
|
|
|
|
if($isBilling == 1)
|
|
{
|
|
$c1->add(UserDataPeer::IS_BILLING, 1);
|
|
}
|
|
else
|
|
{
|
|
$c1->add(UserDataPeer::IS_BILLING, 0);
|
|
}
|
|
|
|
$c1->add(UserDataPeer::IS_DEFAULT, 1);
|
|
|
|
$c2 = new Criteria();
|
|
$c2->add(UserDataPeer::IS_DEFAULT, 0);
|
|
|
|
BasePeer::doUpdate($c1, $c2, $con);
|
|
|
|
$c = new Criteria();
|
|
$c->add(UserDataPeer::SF_GUARD_USER_ID, $this->getUser()->getAttribute('user_id', null, 'sfGuardSecurityUser'));
|
|
$c->add(UserDataPeer::ID, $userDataId);
|
|
|
|
$userData = UserDataPeer::doSelectOne($c);
|
|
|
|
$userData->setIsDefault(1);
|
|
$userData->save();
|
|
|
|
}
|
|
else
|
|
{
|
|
stUser::processAuthentication();
|
|
}
|
|
}
|
|
|
|
/**
|
|
*/
|
|
public function executeSetDefaultProfile()
|
|
{
|
|
if($this->getUser()->isAuthenticated())
|
|
{
|
|
|
|
$userDataId = $this->getRequestParameter('userDataId');
|
|
$userDataType = $this->getRequestParameter('userDataType');
|
|
|
|
$this->setDefaultUserData($userDataId, $this->getUserDataTypeNumericValue($userDataType));
|
|
|
|
$this->redirect('stUserData/editProfile?userDataType='.$userDataType.'&userDataId='.$userDataId.'&showMessage=true');
|
|
}
|
|
else
|
|
{
|
|
stUser::processAuthentication();
|
|
}
|
|
}
|
|
|
|
/**
|
|
*/
|
|
public function getUserDataTypeNumericValue($userDataType)
|
|
{
|
|
if($userDataType == "billing")
|
|
{
|
|
return 1;
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Uchwyt do walidatora tworzenia konta.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function handleErrorCreateFirstUserData()
|
|
{
|
|
$this->smarty = new stSmarty($this->getModuleName());
|
|
|
|
$this->updateUserDataFromRequest();
|
|
return sfView::SUCCESS;
|
|
}
|
|
|
|
protected function updateUserDataFromRequest()
|
|
{
|
|
|
|
$user_config = stConfig::getInstance(sfContext::getInstance(), 'stUser');
|
|
$this->show_region = $user_config->get('show_region');
|
|
$this->show_pesel = $user_config->get('show_pesel');
|
|
$this->show_address_more = $user_config->get('show_address_more');
|
|
|
|
$this->smarty = new stSmarty($this->getModuleName());
|
|
|
|
$userDataBilling = new UserData();
|
|
$userDataDelivery = new UserData();
|
|
|
|
$userDataBillingFromRequest = $this->getRequestParameter('user_data_billing');
|
|
$userDataDeliveryFromRequest = $this->getRequestParameter('user_data_delivery');
|
|
|
|
$userDataBilling->setId($userDataBillingFromRequest['id']);
|
|
$userDataDelivery->setId($userDataDeliveryFromRequest['id']);
|
|
|
|
if (isset($userDataBillingFromRequest['full_name']))
|
|
{
|
|
$userDataBilling->setFullName($userDataBillingFromRequest['full_name']);
|
|
}
|
|
|
|
if (isset($userDataBillingFromRequest['address']))
|
|
{
|
|
$userDataBilling->setAddress($userDataBillingFromRequest['address']);
|
|
}
|
|
|
|
if (isset($userDataBillingFromRequest['address_more']))
|
|
{
|
|
$userDataBilling->setAddressMore($userDataBillingFromRequest['address_more']);
|
|
}
|
|
|
|
if (isset($userDataBillingFromRequest['region']))
|
|
{
|
|
$userDataBilling->setRegion($userDataBillingFromRequest['region']);
|
|
}
|
|
|
|
if (isset($userDataBillingFromRequest['pesel']))
|
|
{
|
|
$userDataBilling->setPesel($userDataBillingFromRequest['pesel']);
|
|
}
|
|
|
|
if (isset($userDataBillingFromRequest['code']))
|
|
{
|
|
$userDataBilling->setCode($userDataBillingFromRequest['code']);
|
|
}
|
|
|
|
if (isset($userDataBillingFromRequest['town']))
|
|
{
|
|
$userDataBilling->setTown($userDataBillingFromRequest['town']);
|
|
}
|
|
|
|
if (isset($userDataBillingFromRequest['country']))
|
|
{
|
|
$userDataBilling->setCountriesId($userDataBillingFromRequest['country']);
|
|
}
|
|
|
|
if (isset($userDataBillingFromRequest['phone']))
|
|
{
|
|
$userDataBilling->setPhone($userDataBillingFromRequest['phone']);
|
|
}
|
|
|
|
if (isset($userDataBillingFromRequest['company']))
|
|
{
|
|
$userDataBilling->setCompany($userDataBillingFromRequest['company']);
|
|
}
|
|
|
|
if (isset($userDataBillingFromRequest['vat_number']))
|
|
{
|
|
$userDataBilling->setVatNumber($userDataBillingFromRequest['vat_number']);
|
|
}
|
|
|
|
if (isset($userDataDeliveryFromRequest['full_name']))
|
|
{
|
|
$userDataDelivery->setFullName($userDataDeliveryFromRequest['full_name']);
|
|
}
|
|
|
|
if (isset($userDataDeliveryFromRequest['address']))
|
|
{
|
|
$userDataDelivery->setAddress($userDataDeliveryFromRequest['address']);
|
|
}
|
|
|
|
if (isset($userDataDeliveryFromRequest['address_more']))
|
|
{
|
|
$userDataDelivery->setAddressMore($userDataDeliveryFromRequest['address_more']);
|
|
}
|
|
|
|
if (isset($userDataDeliveryFromRequest['region']))
|
|
{
|
|
$userDataDelivery->setRegion($userDataDeliveryFromRequest['region']);
|
|
}
|
|
|
|
if (isset($userDataDeliveryFromRequest['code']))
|
|
{
|
|
$userDataDelivery->setCode($userDataDeliveryFromRequest['code']);
|
|
}
|
|
|
|
if (isset($userDataDeliveryFromRequest['town']))
|
|
{
|
|
$userDataDelivery->setTown($userDataDeliveryFromRequest['town']);
|
|
}
|
|
|
|
if (isset($userDataDeliveryFromRequest['country']))
|
|
{
|
|
$userDataDelivery->setCountriesId($userDataDeliveryFromRequest['country']);
|
|
}
|
|
|
|
if (isset($userDataDeliveryFromRequest['phone']))
|
|
{
|
|
$userDataDelivery->setPhone($userDataDeliveryFromRequest['phone']);
|
|
}
|
|
|
|
if (isset($userDataDeliveryFromRequest['company']))
|
|
{
|
|
$userDataDelivery->setCompany($userDataDeliveryFromRequest['company']);
|
|
}
|
|
|
|
|
|
$this->userDataBilling = $userDataBilling;
|
|
$this->userDataDelivery = $userDataDelivery;
|
|
|
|
if ($userDataDeliveryFromRequest['customer_type']==2)
|
|
{
|
|
$this->type1_delivery_checker = 0;
|
|
$this->type2_delivery_checker = 1;
|
|
}
|
|
else
|
|
{
|
|
$this->type1_delivery_checker = 1;
|
|
$this->type2_delivery_checker = 0;
|
|
}
|
|
|
|
if ($userDataBillingFromRequest['customer_type']==2)
|
|
{
|
|
$this->type1_billing_checker = 0;
|
|
$this->type2_billing_checker = 1;
|
|
}
|
|
else
|
|
{
|
|
$this->type1_billing_checker = 1;
|
|
$this->type2_billing_checker = 0;
|
|
}
|
|
|
|
$this->different_delivery = $this->getRequestParameter('different_delivery');
|
|
|
|
|
|
}
|
|
|
|
protected function updateBasketUserData()
|
|
{
|
|
|
|
$user_config = stConfig::getInstance(sfContext::getInstance(), 'stUser');
|
|
$this->show_region = $user_config->get('show_region');
|
|
$this->show_pesel = $user_config->get('show_pesel');
|
|
|
|
$this->smarty = new stSmarty($this->getModuleName());
|
|
|
|
$userDataBillingFromRequest = $this->getRequestParameter('user_data_billing');
|
|
|
|
// if ($userDataBillingFromRequest['customer_billing_type']==2)
|
|
// {
|
|
// $this->type1_billing_checker = 0;
|
|
// $this->type2_billing_checker = 1;
|
|
// }
|
|
// else
|
|
// {
|
|
// $this->type1_billing_checker = 1;
|
|
// $this->type2_billing_checker = 0;
|
|
// }
|
|
|
|
$userDataDeliveryFromRequest = $this->getRequestParameter('user_data_delivery');
|
|
|
|
// if ($userDataDeliveryFromRequest['customer_delivery_type']==2)
|
|
// {
|
|
// $this->type1_delivery_checker = 0;
|
|
// $this->type2_delivery_checker = 1;
|
|
// }
|
|
// else
|
|
// {
|
|
// $this->type1_delivery_checker = 1;
|
|
// $this->type2_delivery_checker = 0;
|
|
// }
|
|
|
|
|
|
$this->userDataBilling = $this->getRequestParameter('user_data_billing');
|
|
|
|
$this->userDataDelivery = $this->getRequestParameter('user_data_delivery');
|
|
|
|
}
|
|
|
|
|
|
public function validateCreateFirstUserData()
|
|
{
|
|
$user_config = stConfig::getInstance(sfContext::getInstance(), 'stUser');
|
|
|
|
$i18n = $this->getContext()->getI18N();
|
|
|
|
$billing = $this->getRequestParameter('user_data_billing', array());
|
|
|
|
if ($this->getRequest()->getMethod() == sfRequest::POST)
|
|
{
|
|
// if (stConfig::getInstance('stPaczkomatyBackend')->get('enable')) {
|
|
// $delivery = stDeliveryFrontend::getInstance(stBasket::getInstance($this->getUser()))->getDefaultDelivery();
|
|
// if (is_object($delivery) && in_array($delivery->getPaczkomatyType(), array('ALL', 'COD'))) {
|
|
// $user_config->set('validate_phone', 1);
|
|
//
|
|
// if (!$billing['paczkomaty_machine_number']) {
|
|
// $this->getRequest()->setError('user_data_billing{paczkomaty_machine_number}', true);
|
|
// $error_exists = true;
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
if ($billing['customer_type']==2)
|
|
{
|
|
if (!$billing['company'])
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{company}', $i18n->__('Brak firmy.'));
|
|
}
|
|
|
|
if (!$billing['vat_number'])
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{vat_number}', $i18n->__('Brak nipu.'));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!$billing['full_name'])
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{full_name}', $i18n->__('Brak imienia i nazwiska.'));
|
|
}
|
|
}
|
|
|
|
if (!$billing['phone'] && $user_config->get('validate_phone')==1)
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{phone}', $i18n->__('Brak telefonu.'));
|
|
}
|
|
|
|
if ($this->hasRequestParameter('different_delivery'))
|
|
{
|
|
$delivery = $this->getRequestParameter('user_data_delivery', array());
|
|
|
|
$validator = new sfStringValidator();
|
|
$validator->initialize($this->getContext(), array(
|
|
'max' => 255,
|
|
'max_error' => $i18n->__('Przekroczono dozwoloną liczbę znaków.'),
|
|
|
|
));
|
|
|
|
|
|
if ($delivery['customer_type']==2)
|
|
{
|
|
if (!$delivery['company'])
|
|
{
|
|
$this->getRequest()->setError('user_data_delivery{company}', $i18n->__('Brak firmy.'));
|
|
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
if (!$delivery['full_name'])
|
|
{
|
|
$this->getRequest()->setError('user_data_delivery{full_name}', $i18n->__('Brak imienia i nazwiska.'));
|
|
|
|
}
|
|
}
|
|
|
|
if (!$delivery['address'])
|
|
{
|
|
$this->getRequest()->setError('user_data_delivery{address}', $i18n->__('Brak adresu.'));
|
|
}
|
|
|
|
if (!$delivery['code'])
|
|
{
|
|
$this->getRequest()->setError('user_data_delivery{code}', $i18n->__('Brak kodu.'));
|
|
}
|
|
|
|
if (!$delivery['town'])
|
|
{
|
|
$this->getRequest()->setError('user_data_delivery{town}', $i18n->__('Brak miasta.'));
|
|
}
|
|
|
|
if (!$delivery['phone'] && $user_config->get('validate_phone')==1)
|
|
{
|
|
$this->getRequest()->setError('user_data_delivery{phone}', $i18n->__('Brak telefonu.'));
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
return !$this->getRequest()->hasErrors();
|
|
}
|
|
|
|
public function validateAddBasketUser()
|
|
{
|
|
if ($this->getRequest()->getMethod() != sfRequest::POST)
|
|
{
|
|
throw new sfUnprocessableEntityException();
|
|
}
|
|
|
|
$user_data_billing = $this->getRequestParameter('user_data_billing');
|
|
$user_data_delivery = $this->getRequestParameter('user_data_delivery');
|
|
|
|
if (null === $user_data_billing || null === $user_data_delivery)
|
|
{
|
|
throw new sfUnprocessableEntityException();
|
|
}
|
|
|
|
$error_exists = false;
|
|
$deliveryErrors = [];
|
|
$paymentErrors = [];
|
|
$i18n = $this->getContext()->getI18N();
|
|
$user_config = stConfig::getInstance('stUser');
|
|
$invoice_config = stConfig::getInstance('stInvoiceBackend');
|
|
/**
|
|
* @var stBasket
|
|
*/
|
|
$basket = $this->getUser()->getBasket();
|
|
$frontendDelivery = stDeliveryFrontend::getInstance($basket);
|
|
$frontendDelivery->setDefaultDeliveryCountry($this->getRequest()->getParameter('delivery_country_id'));
|
|
|
|
if (null === $frontendDelivery->getDefaultDeliveryCountry())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
$frontendDelivery->setDefaultDelivery($this->getRequest()->getParameter('delivery_id'));
|
|
$delivery = $frontendDelivery->getDefaultDelivery();
|
|
|
|
if (null === $frontendDelivery->getDefaultDelivery())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
$frontendDelivery->getDefaultDelivery()->setDefaultPayment($this->getRequest()->getParameter('payment_id'));
|
|
|
|
if (null === $frontendDelivery->getDefaultDelivery()->getDefaultPayment())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
$totalBasketAmount = $basket->getTotalAmount(true);
|
|
$orderTotalAmount = $frontendDelivery->getTotalDeliveryCost(true) + $basket->getTotalAmount(true);
|
|
|
|
$pickupPoint = stDeliveryTypePickupPoint::createFromJson($this->getRequestParameter('delivery_pickup_point'));
|
|
|
|
$user_data_billing = array_map('trim', $user_data_billing);
|
|
$user_data_delivery = array_map('trim', $user_data_delivery);
|
|
|
|
$this->getRequest()->setParameter('user_data_billing', $user_data_billing);
|
|
$this->getRequest()->setParameter('user_data_delivery', $user_data_delivery);
|
|
$isCustomerAccount = isset($user_data_billing['different_delivery']) ? $user_data_delivery['customer_type'] == 1 : $user_data_billing['customer_type'] == 1;
|
|
|
|
|
|
if ($user_data_billing)
|
|
{
|
|
if ($this->getUser()->hasVatEu())
|
|
{
|
|
$user_data_billing['customer_type'] = 2;
|
|
}
|
|
|
|
if (!isset($user_data_billing['create_account']))
|
|
{
|
|
$user_data_billing['create_account'] = 0;
|
|
}
|
|
|
|
if (!isset($user_data_billing['privacy']))
|
|
{
|
|
$user_data_billing['privacy'] = 0;
|
|
}
|
|
|
|
if (!isset($user_data_billing['different_delivery']) && !$this->getUser()->isAuthenticated())
|
|
{
|
|
$user_data_billing['different_delivery'] = 0;
|
|
$user_data_delivery['customer_type'] = $user_data_billing['customer_type'];
|
|
$user_data_delivery['company'] = $user_data_billing['company'];
|
|
if (isset($user_data_billing['pesel']))
|
|
{
|
|
$user_data_delivery['pesel'] = $user_data_billing['pesel'];
|
|
}
|
|
$user_data_delivery['full_name'] = $user_data_billing['full_name'];
|
|
$user_data_delivery['address'] = $user_data_billing['address'];
|
|
$user_data_delivery['code'] = $user_data_billing['code'];
|
|
$user_data_delivery['town'] = $user_data_billing['town'];
|
|
if (isset($user_data_billing['region']))
|
|
{
|
|
$user_data_delivery['region'] = $user_data_billing['region'];
|
|
}
|
|
$user_data_delivery['country'] = $user_data_billing['country'];
|
|
$user_data_delivery['phone'] = $user_data_billing['phone'];
|
|
}
|
|
|
|
if ($this->getUser()->isAuthenticated() && isset($user_data_billing['paczkomaty_machine_number']) && !empty($user_data_billing['paczkomaty_machine_number']))
|
|
{
|
|
$user_data_delivery['phone'] = $user_data_billing['phone'];
|
|
}
|
|
|
|
|
|
if (isset($user_data_billing['email']))
|
|
{
|
|
$user_data_billing['email'] = trim($user_data_billing['email']);
|
|
|
|
$c = new Criteria();
|
|
|
|
$c->add(sfGuardUserPeer::USERNAME, $user_data_billing['email']);
|
|
$user = sfGuardUserPeer::doSelectOne($c);
|
|
|
|
if ($user)
|
|
{
|
|
if (stUser::isFullAccount($user_data_billing['email']) && $user_data_billing['create_account'] == 1)
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{email}', $i18n->__('Taki użytkownik już istnieje.'));
|
|
}
|
|
}
|
|
|
|
$valid = filter_var($user_data_billing['email'], FILTER_VALIDATE_EMAIL);
|
|
|
|
if (!$valid)
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{email}', $i18n->__('Niepoprawny adres.'));
|
|
}
|
|
}
|
|
|
|
if (!$user_data_billing['full_name'] && ($user_data_billing['customer_type'] == 1 || $user_config->get('require_billing_fullname')))
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{full_name}', $i18n->__('Brak imienia i nazwiska.'));
|
|
}
|
|
|
|
|
|
if (!$user_data_billing['company'] && $user_data_billing['customer_type'] == 2)
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{company}', $i18n->__('Brak firmy.'));
|
|
}
|
|
|
|
if (!$user_data_billing['vat_number'] && $user_data_billing['customer_type'] == 2)
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{vat_number}', $this->getUser()->hasVatEu() ? 'Brak numeru VAT UE.' : 'Brak numeru NIP.');
|
|
}
|
|
|
|
if (!$this->getUser()->isAuthenticated())
|
|
{
|
|
if (!isset($user_data_billing['email']) || !$user_data_billing['email'])
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{email}', $i18n->__('Brak adresu email.'));
|
|
}
|
|
}
|
|
|
|
if (isset($user_data_billing['create_account']) && $user_data_billing['create_account'] && !$this->getUser()->isAuthenticated())
|
|
{
|
|
|
|
if ($user_data_billing['password1'] != $user_data_billing['password2'])
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{password1}', $i18n->__('Hasła nie są takie same.'));
|
|
$this->getRequest()->setError('user_data_billing{password2}', $i18n->__('Hasła nie są takie same.'));
|
|
}
|
|
|
|
if (!$user_data_billing['password1'])
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{password1}', $i18n->__('Brak hasła.'));
|
|
}
|
|
|
|
if (!$user_data_billing['password2'])
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{password2}', $i18n->__('Brak hasła.'));
|
|
}
|
|
|
|
if (stTheme::is_responsive())
|
|
{
|
|
|
|
if ($user_data_billing['privacy'] != 1)
|
|
{
|
|
$this->getRequest()->setError('error_privacy', 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!isset($user_data_billing['address']) || !$user_data_billing['address'])
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{address}', $i18n->__('Brak adresu.'));
|
|
}
|
|
|
|
if (!isset($user_data_billing['code']) || !$user_data_billing['code'])
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{code}', $i18n->__('Brak kodu.'));
|
|
}
|
|
|
|
if (!isset($user_data_billing['town']) || !$user_data_billing['town'])
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{town}', $i18n->__('Brak miasta.'));
|
|
}
|
|
|
|
if ((!isset($user_data_billing['phone']) || !$user_data_billing['phone']) && $user_config->get('validate_phone') == 1)
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{phone}', $i18n->__('Brak telefonu.'));
|
|
}
|
|
|
|
if (null === $delivery->getService() || !$delivery->getService()->isPickupPoint())
|
|
{
|
|
if (isset($user_data_billing['different_delivery']) && $user_data_billing['different_delivery'] == 1 || $this->getUser()->isAuthenticated())
|
|
{
|
|
if (!$user_data_delivery['company'] && $user_data_delivery['customer_type'] == 2)
|
|
{
|
|
$this->getRequest()->setError('user_data_delivery{company}', $i18n->__('Brak firmy.'));
|
|
}
|
|
|
|
if (!$user_data_delivery['full_name'] && $user_data_delivery['customer_type'] == 1)
|
|
{
|
|
$this->getRequest()->setError('user_data_delivery{full_name}', $i18n->__('Brak imienia i nazwiska.'));
|
|
}
|
|
|
|
if (!$user_data_delivery['address'])
|
|
{
|
|
$this->getRequest()->setError('user_data_delivery{address}', $i18n->__('Brak adresu.'));
|
|
}
|
|
|
|
if (!$user_data_delivery['code'])
|
|
{
|
|
$this->getRequest()->setError('user_data_delivery{code}', $i18n->__('Brak kodu.'));
|
|
}
|
|
|
|
if (!$user_data_delivery['town'])
|
|
{
|
|
$this->getRequest()->setError('user_data_delivery{town}', $i18n->__('Brak miasta.'));
|
|
}
|
|
|
|
if (!$user_data_delivery['phone'] && $user_config->get('validate_phone') == 1)
|
|
{
|
|
$this->getRequest()->setError('user_data_delivery{phone}', $i18n->__('Brak telefonu.'));
|
|
}
|
|
|
|
if ($user_data_delivery['country'] != $frontendDelivery->getDefaultDeliveryCountry()->getId())
|
|
{
|
|
$this->getRequest()->setError('user_data_delivery{country}', $i18n->__('Wybrany kraj nie może się różnić od kraju dostawy'));
|
|
}
|
|
|
|
if ($this->getUser()->hasVatEu() && $invoice_config->get('check_vat_eu_delivery_country', true))
|
|
{
|
|
$deliveryCountry = CountriesPeer::retrieveById($user_data_delivery['country']);
|
|
list($cc) = stTaxVies::parseVatNumber($user_data_billing['vat_number']);
|
|
|
|
$ccEuFix = array('EL' => 'GR', 'CHE' => 'CH');
|
|
|
|
if (isset($ccEuFix[$cc]))
|
|
{
|
|
$cc = $ccEuFix[$cc];
|
|
}
|
|
|
|
if ($deliveryCountry->getIsoA2() != $cc)
|
|
{
|
|
$this->getRequest()->setError('user_data_delivery{country}', $i18n->__('Wybrany kraj nie jest zgodny z podanym numerem VAT UE'));
|
|
$this->getUser()->setValidVatEu(false);
|
|
}
|
|
else
|
|
{
|
|
$this->getUser()->setValidVatEu(true);
|
|
}
|
|
}
|
|
}
|
|
elseif ($user_data_billing['country'] != $frontendDelivery->getDefaultDeliveryCountry()->getId())
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{country}', $i18n->__('Wybrany kraj nie może się różnić od kraju dostawy'));
|
|
}
|
|
}
|
|
|
|
if (!stTheme::is_responsive())
|
|
{
|
|
|
|
if (!$this->getUser()->isAuthenticated())
|
|
{
|
|
|
|
if ($user_data_billing['privacy'] == 1)
|
|
{
|
|
$user_data_billing['terms'] = 1;
|
|
}
|
|
else
|
|
{
|
|
$this->getRequest()->setError('error_privacy', 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!$this->getUser()->isAuthenticated() && !isset($user_data_billing['terms']))
|
|
{
|
|
$this->getRequest()->setError('error_terms', 1);
|
|
}
|
|
else
|
|
{
|
|
if (!$this->getUser()->isAuthenticated())
|
|
{
|
|
$captcha_mod = stConfig::getInstance('stSecurityBackend')->get('captcha_mod');
|
|
|
|
if ($captcha_mod == "recaptcha3" && sfContext::getInstance()->getUser()->getAttribute('badscore') != 1)
|
|
{
|
|
$recaptcha_secret = stConfig::getInstance('stSecurityBackend')->get('recaptcha_secret');
|
|
|
|
// Build POST request:
|
|
$recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify';
|
|
$recaptcha_secret = $recaptcha_secret;
|
|
$recaptcha_response = $this->getRequestParameter('recaptcha_response');
|
|
|
|
// Make and decode POST request:
|
|
$recaptcha = file_get_contents($recaptcha_url . '?secret=' . $recaptcha_secret . '&response=' . $recaptcha_response);
|
|
$recaptcha = json_decode($recaptcha);
|
|
|
|
|
|
if ($recaptcha->score <= 0.5)
|
|
{
|
|
// Bad score
|
|
$captcha_mod == "standart";
|
|
$this->getUser()->setAttribute('badscore', true);
|
|
}
|
|
else
|
|
{
|
|
$this->getUser()->setAttribute('badscore', false);
|
|
}
|
|
}
|
|
|
|
if ($captcha_mod == "standart" || sfContext::getInstance()->getUser()->getAttribute('badscore') == 1)
|
|
{
|
|
|
|
$validator = new stCaptchaGDValidator();
|
|
|
|
$validator->initialize($this->getContext(), array('captcha_error' => 'Wprowadzono zły numer.'));
|
|
|
|
$captcha = $this->getRequestParameter('captcha');
|
|
|
|
if (!$validator->execute($captcha, $error) && $this->getUser()->getAttribute('captcha_off') != 1)
|
|
{
|
|
$this->getRequest()->setError('captcha', $error);
|
|
}
|
|
else
|
|
{
|
|
$this->getUser()->setAttribute('captcha_off', true);
|
|
$this->getUser()->setAttribute('badscore', false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if ($delivery->getDefaultPayment()->getPaymentType()->getModuleName() == 'stEservice')
|
|
{
|
|
if (!$user_data_billing['full_name'])
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{full_name}', $i18n->__('Brak imienia i nazwiska.'));
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$error_exists = true;
|
|
}
|
|
|
|
foreach (stGiftCardPlugin::get() as $giftCard)
|
|
{
|
|
if (!stGiftCardPlugin::hasValidBasketProducts($giftCard, $invalidItemIds))
|
|
{
|
|
foreach ($invalidItemIds as $id)
|
|
{
|
|
$this->getRequest()->setError('basket{products}{' . $id . '}', $this->getContext()->getI18N()->__('Usuń produkt z koszyka, aby zrealizować zamówienie z aktualnym bonem zakupowym', null, 'stGiftCardFrontend'));
|
|
}
|
|
|
|
$error_exists = true;
|
|
}
|
|
elseif (!$giftCard->isValidOrderAmount($basket->getTotalAmount(true, true)))
|
|
{
|
|
$error_exists = true;
|
|
}
|
|
}
|
|
|
|
$basketItemValidator = new stBasketItemValidator($basket);
|
|
$basketItemValidator->initialize($this->getContext());
|
|
|
|
foreach ($basket->getItems() as $item)
|
|
{
|
|
if (!$basketItemValidator->execute($item, $error))
|
|
{
|
|
$this->getRequest()->setError('basket{products}{' . $item->getItemId() . '}', $error);
|
|
}
|
|
}
|
|
|
|
$validator = new stOrderMinAmountValidator();
|
|
$validator->initialize($this->getContext(), [
|
|
'country' => $frontendDelivery->getDefaultDeliveryCountry(),
|
|
'is_customer' => $isCustomerAccount
|
|
]);
|
|
|
|
if (!$validator->execute($totalBasketAmount, $error))
|
|
{
|
|
$error_exists = true;
|
|
$this->setFlash('warning', $error, false);
|
|
}
|
|
|
|
if ($this->getUser()->hasVatEu() && !$this->getRequest()->hasError('user_data_billing{vat_number}'))
|
|
{
|
|
$shopInfoConfig = stConfig::getInstance('stShopInfoBackend');
|
|
$billingCountry = CountriesPeer::retrieveById($user_data_billing['country']);
|
|
list($cc) = stTaxVies::parseVatNumber($user_data_billing['vat_number']);
|
|
|
|
$ccEuFix = array('EL' => 'GR', 'CHE' => 'CH');
|
|
|
|
if (isset($ccEuFix[$cc]))
|
|
{
|
|
$cc = $ccEuFix[$cc];
|
|
}
|
|
|
|
if (!stTaxVies::hasValidCountryCode($user_data_billing['vat_number'], $shopInfoConfig->get('country')))
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{vat_number}', $i18n->__('Podany numer VAT UE nie spełnia wymogów wewnątrzwspólnotowego nabycia towarów', null, 'stUserData'));
|
|
$this->getUser()->setValidVatEu(false);
|
|
}
|
|
elseif ($billingCountry->getIsoA2() != $cc)
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{country}', $i18n->__('Wybrany kraj nie jest zgodny z podanym numerem VAT UE'));
|
|
$this->getUser()->setValidVatEu(false);
|
|
}
|
|
elseif (!$error_exists && !$this->getRequest()->hasErrors() && !stTaxVies::getInstance()->checkVat($user_data_billing['vat_number']))
|
|
{
|
|
if (null !== stTaxVies::getInstance()->getSoapFault())
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{vat_number}', $i18n->__('Wystąpił problem z połączeniem z serwisem VIES.'));
|
|
}
|
|
else
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{vat_number}', $i18n->__('Podany numer VAT UE jest nieaktywny lub nieprawidłowy'));
|
|
}
|
|
|
|
$this->getUser()->setValidVatEu(false);
|
|
}
|
|
else
|
|
{
|
|
$this->getUser()->setValidVatEu(true);
|
|
}
|
|
}
|
|
|
|
if (null !== $delivery->getDefaultPayment())
|
|
{
|
|
$payment = $delivery->getDefaultPayment();
|
|
|
|
if (null !== $delivery->getService())
|
|
{
|
|
$valid = $delivery->getService()->validate($delivery->getDelivery(),
|
|
$payment->getDeliveryPayment()->getPaymentType(),
|
|
$orderTotalAmount,
|
|
$user_data_billing,
|
|
$user_data_delivery,
|
|
$pickupPoint,
|
|
$frontendDelivery->getIsWeekendDelivery(),
|
|
$frontendDelivery->getIsExpressDelivery(),
|
|
$deliveryErrors
|
|
);
|
|
|
|
if (!$valid)
|
|
{
|
|
foreach ($deliveryErrors as $name => $error)
|
|
{
|
|
$this->getRequest()->setError($name, $i18n->__($error));
|
|
}
|
|
}
|
|
}
|
|
|
|
if (null !== $payment->getPaymentTypeApi() && $payment->getPaymentTypeApi() instanceof stPaymentTypeInterface && !$payment->getPaymentTypeApi()->validate($user_data_billing, $user_data_delivery, $orderTotalAmount, $paymentErrors))
|
|
{
|
|
foreach ($paymentErrors as $name => $error)
|
|
{
|
|
$this->getRequest()->setError($name, $error);
|
|
}
|
|
}
|
|
}
|
|
|
|
return !$error_exists && !$this->getRequest()->hasErrors();
|
|
}
|
|
|
|
public function validateCheckBasketUser()
|
|
{
|
|
$error_exists = false;
|
|
|
|
$i18n = $this->getContext()->getI18N();
|
|
|
|
$billing = $this->getRequestParameter('user_data_billing', array());
|
|
|
|
$delivery = $this->getRequestParameter('user_data_delivery', array());
|
|
|
|
if ($billing['company'] || $billing['vatNumber'])
|
|
{
|
|
if (!$billing['company'])
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{company}', $i18n->__('Brak firmy.'));
|
|
$error_exists = true;
|
|
}
|
|
|
|
if (!$billing['vatNumber'])
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{vatNumber}', $i18n->__('Brak nipu.'));
|
|
$error_exists = true;
|
|
}
|
|
}
|
|
|
|
if (!$billing['company'] && !$billing['vatNumber'] && !$billing['full_name'])
|
|
{
|
|
$this->getRequest()->setError('user_data_billing{message}', $i18n->__('Musisz podać imię i nazwisko lub dane firmowe.'));
|
|
$this->getRequest()->setError('user_data_billing{full_name}','');
|
|
$this->getRequest()->setError('user_data_billing{company}','');
|
|
$this->getRequest()->setError('user_data_billing{vatNumber}','');
|
|
$error_exists = true;
|
|
}
|
|
|
|
|
|
|
|
if (!$delivery['company'] && !$delivery['full_name'])
|
|
{
|
|
$this->getRequest()->setError('user_data_delivery{message}', $i18n->__('Musisz podać imię i nazwisko lub nazwę firmy.'));
|
|
$this->getRequest()->setError('user_data_delivery{full_name}','');
|
|
$this->getRequest()->setError('user_data_delivery{company}','');
|
|
$error_exists = true;
|
|
}
|
|
|
|
return !$error_exists;
|
|
}
|
|
|
|
public function validateSaveProfile()
|
|
{
|
|
|
|
$error_exists = false;
|
|
|
|
$i18n = $this->getContext()->getI18N();
|
|
|
|
$user_data = $this->getRequestParameter('user_data', array());
|
|
|
|
$user_config = stConfig::getInstance(sfContext::getInstance(), 'stUser');
|
|
|
|
if($user_data['isBilling']==1)
|
|
{
|
|
|
|
if($user_data['customer_type']==2)
|
|
{
|
|
if (!$user_data['company'])
|
|
{
|
|
$this->getRequest()->setError('user_data{company}', $i18n->__('Brak firmy.'));
|
|
}
|
|
|
|
if (!$user_data['vat_number'])
|
|
{
|
|
$this->getRequest()->setError('user_data{vat_number}', $i18n->__('Brak nipu.'));
|
|
}
|
|
}
|
|
|
|
if($user_data['customer_type']==1)
|
|
{
|
|
if (!$user_data['full_name'])
|
|
{
|
|
$this->getRequest()->setError('user_data{full_name}', $i18n->__('Brak imienia i nazwiska.'));
|
|
}
|
|
}
|
|
|
|
|
|
}else{
|
|
if($user_data['customer_type']==2)
|
|
{
|
|
if (!$user_data['company'])
|
|
{
|
|
$this->getRequest()->setError('user_data{company}', $i18n->__('Brak firmy.'));
|
|
}
|
|
}
|
|
|
|
if($user_data['customer_type']==1)
|
|
{
|
|
if (!$user_data['full_name'])
|
|
{
|
|
$this->getRequest()->setError('user_data{full_name}', $i18n->__('Brak imienia i nazwiska.'));
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!$user_data['phone'] && $user_config->get('validate_phone')==1)
|
|
{
|
|
$this->getRequest()->setError('user_data{phone}', $i18n->__('Brak telefonu.'));
|
|
}
|
|
|
|
|
|
return !$this->getRequest()->hasErrors();
|
|
}
|
|
|
|
|
|
/**
|
|
* Usuwanie profilu
|
|
*/
|
|
public function executeAddBasketUser()
|
|
{
|
|
if ($this->getRequest()->getMethod() == sfRequest::POST)
|
|
{
|
|
|
|
$this->forward('stOrder', 'confirm');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Usuwanie profilu
|
|
*/
|
|
public function executeCheckBasketUser()
|
|
{
|
|
if ($this->getRequest()->getMethod() == sfRequest::POST)
|
|
{
|
|
$this->forward('stOrder', 'confirm');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Uchwyt do walidatora tworzenia konta.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function handleErrorAddBasketUser()
|
|
{
|
|
$this->updateBasketUserData();
|
|
|
|
return $this->forward('stBasket', 'index');
|
|
}
|
|
|
|
/**
|
|
* Uchwyt do walidatora tworzenia konta.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function handleErrorCheckBasketUser()
|
|
{
|
|
$this->smarty = new stSmarty($this->getModuleName());
|
|
|
|
return $this->forward('stBasket', 'index');
|
|
}
|
|
|
|
/**
|
|
* Uchwyt do walidatora tworzenia konta.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function handleErrorSaveProfile()
|
|
{
|
|
$this->smarty = new stSmarty($this->getModuleName());
|
|
|
|
return $this->forward('stUserData', 'editProfile');
|
|
}
|
|
|
|
|
|
public function isMyUserData($userDataId)
|
|
{
|
|
$c = new Criteria();
|
|
$c->add(UserDataPeer::ID, $userDataId);
|
|
$c->add(UserDataPeer::SF_GUARD_USER_ID , $this->getUser()->getAttribute('user_id', null, 'sfGuardSecurityUser'));
|
|
$userData = UserDataPeer::doSelectOne($c);
|
|
|
|
|
|
if (!$userData)
|
|
{
|
|
$this->forward404();
|
|
}
|
|
|
|
}
|
|
|
|
public function executeAjaxProfileChange()
|
|
{
|
|
$id = $this->getRequestParameter('id');
|
|
|
|
$type = $this->getRequestParameter('type');
|
|
|
|
if($type=="billing")
|
|
{
|
|
$this->getUser()->setAttribute('customer_type', null, 'soteshop/stUserData');
|
|
stUser::setDefaultUserData($id, 1, $this->getUser()->getGuardUser()->getId());
|
|
$this->responseUpdateElement('user_'.$type.'_form_content', array(
|
|
'module' => 'stUserData',
|
|
'component' => 'orderFormBilling',
|
|
'params' => array(
|
|
'profile_id' => $id,
|
|
'type' => $type,
|
|
'force_default' => true,
|
|
),
|
|
));
|
|
}
|
|
|
|
if($type=="user_edit_profile_billing")
|
|
{
|
|
|
|
$this->responseUpdateElement('user_edit_profile_content', array('module' => 'stUserData', 'component' => 'ajaxEditProfile', 'params' => array('profile_id' => $id, 'type' => $type)));
|
|
}
|
|
|
|
|
|
if($type=="delivery")
|
|
{
|
|
stUser::setDefaultUserData($id, 0, $this->getUser()->getGuardUser()->getId());
|
|
$this->responseUpdateElement('user_'.$type.'_form_content', array(
|
|
'module' => 'stUserData',
|
|
'component' => 'orderFormDelivery',
|
|
'params' => array(
|
|
'profile_id' => $id,
|
|
'type' => $type,
|
|
'force_default' => true,
|
|
),
|
|
));
|
|
}
|
|
|
|
if($type=="user_edit_profile_delivery")
|
|
{
|
|
$this->responseUpdateElement('user_edit_profile_content', array('module' => 'stUserData', 'component' => 'ajaxEditProfile', 'params' => array('profile_id' => $id, 'type' => $type)));
|
|
}
|
|
|
|
return $this->renderResponse();
|
|
}
|
|
|
|
public function executeAddressList()
|
|
{
|
|
$this->smarty = new stSmarty($this->getModuleName());
|
|
|
|
if($this->getUser()->isAuthenticated())
|
|
{
|
|
|
|
stUser::deleteEmptyUserData($this->getUser()->getAttribute('user_id', null, 'sfGuardSecurityUser'));
|
|
|
|
$userDataBillingDefault = $this->getUser()->getUserData(true, true);
|
|
foreach($userDataBillingDefault as $data)
|
|
{
|
|
$data->url_edit = st_url_for('stUserData/editProfile?userDataType=billing&userDataId=' . $data->getId() . '&showEditProfileForm=true');
|
|
$data->url_delete = st_url_for('stUserData/deleteProfile?userDataType=billing&userDataId='.$data->getId());
|
|
}
|
|
|
|
$userDataBilling = $this->getUser()->getUserData(false, true);
|
|
foreach($userDataBilling as $data)
|
|
{
|
|
if(empty($data->getAddress())){
|
|
return false; // Usuń ten obiekt
|
|
}
|
|
|
|
$data->url_edit = st_url_for('stUserData/editProfile?userDataType=billing&userDataId=' . $data->getId() . '&showEditProfileForm=true');
|
|
$data->url_delete = st_url_for('stUserData/deleteProfile?userDataType=billing&userDataId='.$data->getId());
|
|
}
|
|
|
|
|
|
$userDataDeliveryDefault = $this->getUser()->getUserData(true, false);
|
|
foreach($userDataDeliveryDefault as $data)
|
|
{
|
|
$data->url_edit = st_url_for('stUserData/editProfile?userDataType=delivery&userDataId=' . $data->getId() . '&showEditProfileForm=true');
|
|
$data->url_delete = st_url_for('stUserData/deleteProfile?userDataType=delivery&userDataId='.$data->getId());
|
|
}
|
|
|
|
$userDataDelivery = $this->getUser()->getUserData(false, false);
|
|
foreach($userDataDelivery as $data)
|
|
{
|
|
if(empty($data->getAddress())){
|
|
return false; // Usuń ten obiekt
|
|
}
|
|
|
|
$data->url_edit = st_url_for('stUserData/editProfile?userDataType=delivery&userDataId=' . $data->getId() . '&showEditProfileForm=true');
|
|
$data->url_delete = st_url_for('stUserData/deleteProfile?userDataType=delivery&userDataId='.$data->getId());
|
|
}
|
|
|
|
/*echo "<pre>";
|
|
print_r($userDataBilling);*/
|
|
|
|
$this->userDataBillingDefault = $userDataBillingDefault;
|
|
$this->userDataBilling = $userDataBilling;
|
|
$this->userDataDeliveryDefault = $userDataDeliveryDefault;
|
|
$this->userDataDelivery = $userDataDelivery;
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
stUser::processAuthentication();
|
|
}
|
|
}
|
|
|
|
public function executeProductList()
|
|
{
|
|
$this->smarty = new stSmarty($this->getModuleName());
|
|
$type = $this->getFilteredRequestParameter('type', sfDataFilterPlainTextType::class);
|
|
$this->type = $type;
|
|
|
|
$allowed = ['last', 'observe'];
|
|
if (!in_array($type, $allowed, true)) {
|
|
throw new sfException(sprintf(
|
|
'Bad type "%s". Allowed types are: %s.',
|
|
$type,
|
|
implode(', ', $allowed)
|
|
));
|
|
}
|
|
|
|
stProductFilter::disable();
|
|
|
|
$ids = array();
|
|
|
|
$this->is_authenticated = $this->getUser()->isAuthenticated();
|
|
|
|
if($type == "last")
|
|
{
|
|
$this->tab = 8;
|
|
|
|
$utd_cookie = stUserTrackerLevelInterface::getUTDCookie();
|
|
|
|
if(isset($utd_cookie['product_view_recently']) && !empty($utd_cookie['product_view_recently']))
|
|
{
|
|
$ids = $utd_cookie['product_view_recently'];
|
|
$ids = array_reverse($ids);
|
|
}
|
|
}
|
|
|
|
if($type == "observe")
|
|
{
|
|
$this->tab = 9;
|
|
|
|
$utd_cookie = stUserTrackerLevelInterface::getUTDCookie();
|
|
|
|
if(isset($utd_cookie['product_observe']))
|
|
{
|
|
$ids = $utd_cookie['product_observe'];
|
|
$ids = array_reverse($ids);
|
|
}
|
|
}
|
|
|
|
if($ids)
|
|
{
|
|
// złącz listę ID w ciąg "1,2,3,4"
|
|
$inList = implode(',', $ids);
|
|
|
|
$c = new Criteria();
|
|
$c -> add(ProductPeer::ACTIVE, 1);
|
|
$c->add(ProductPeer::ID, $ids, Criteria::IN);
|
|
$c->addAscendingOrderByColumn("FIELD(" . ProductPeer::ID . ", $inList)");
|
|
$c->setLimit(100);
|
|
|
|
$this->productPagerInit($c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
protected function productPagerInit(Criteria $c)
|
|
{
|
|
|
|
$config = stConfig::getInstance(sfContext::getInstance(), 'stProduct');
|
|
|
|
$this->product_pager = new stPropelPager('Product', $config->get('long_list'));
|
|
|
|
$c = clone $c;
|
|
|
|
$this->product_pager->setPage($this->getFilteredRequestParameter('page', sfDataFilterIntType::class));
|
|
|
|
$this->product_pager->setCriteria($c);
|
|
|
|
$this->product_pager->setPeerMethod('doSelect');
|
|
|
|
$this->product_pager->init();
|
|
}
|
|
}
|