<?php
namespace App\OfficeBrain\Bundle\SearchBundle\Form\Data;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Doctrine\ORM\EntityManager;
use OfficeBrain\Bundle\CategoryBundle\Entity\CultureCategory;
use Doctrine\Common\Collections\ArrayCollection;
class ProductSearchData
{
private $country;
private $tag;
private $categoryId;
private $categorySlug;
private $supplierId;
private $brandId;
private $minPrice;
private $minPriceWithoutLogin;
private $maxPrice;
private $minQty;
private $maxQty;
private $pageNumber;
private $sortOn;
private $sortOrder;
private $keyword;
private $attribute;
private $sort;
private $searchType;
private $catalogYear;
private $priceValidUntil;
// TODO added for promocan api
private $lineNameId;
private $priceCurrency;
private $quantity;
private $sku;
private $em;
private $languageCode;
private $callForPrice;
private $lineName;
private $categoryName;
private $postName;
private $supplierName;
private $supplier;
private $distributorId;
private $customCategoryId;
private $productId;
private $instanceId;
private $userRole;
private $userId;
private $rating;
private $productAttribute;
private $publicCustomTagText;
private $privateCustomTagText;
private $colorMapping;
private $serviceGroupId;
private $categoryIdNot;
private $productIdNot;
private $tagNot;
private $categoryTagId;
private $categoryTag;
private $quoteSearch;
private $similarSku;
public function __construct(EntityManager $em, $languageCode = '1')
{
$this->em = $em;
$this->languageCode = $languageCode;
}
public static function toSolrSupportedArray($object)
{
$returnArray = array();
foreach (get_class_vars(get_class($object)) as $key=>$value) {
$tmpKey = trim(strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $key)));
$returnArray[$tmpKey] = (in_array($key, array( "brandId"))? (isset($object->$key)?array($object->$key):null) : $object->$key);
}
return $returnArray;
}
/**
* @Assert\Callback
*/
public function validate(ExecutionContextInterface $context)
{
if ($this->getCategorySlug()!="") {
$result = $this->em->getRepository('App\OfficeBrain\Bundle\CategoryBundle\Entity\CultureCategory')->findOneBy(array('slug'=>$this->getCategorySlug(), 'culture'=>$this->languageCode));
if (!$result) {
$context->addViolationAt(
'categorySlug',
'Please provide valid category slug.',
array(),
null
);
} else {
$this->setCategoryId($result->getCat()->getId());
}
}
}
public function getCategoryTagId()
{
return $this->categoryTagId;
}
public function setCategoryTagId($categoryTagId)
{
$this->categoryTagId = $categoryTagId;
return $this;
}
public function getCategoryTag()
{
return $this->categoryTag;
}
public function setCategoryTag($categoryTag)
{
$this->categoryTag = $categoryTag;
return $this;
}
public function getQuoteSearch()
{
return $this->quoteSearch;
}
public function setQuoteSearch($quoteSearch)
{
$this->quoteSearch = $quoteSearch;
return $this;
}
/************************************Solr call api starts*******************************************/
public function init($apiCallType)
{
$this->isError = false;
$this->apiCallType = trim($apiCallType);
}
public function setSearchKeyword($searchKeyword)
{
$this->searchKeyword = trim($searchKeyword);
}
public function setAttributeFilter($attributeFilter)
{
$attributeFilter = trim($attributeFilter);
if ($attributeFilter) {
$this->attributeFilter = $this->parseAttribute($attributeFilter);
}
}
private function parseAttribute($attributeFilter)
{
$attributeFilterArray = array();
$attributeFilter = json_decode($attributeFilter);
foreach ($attributeFilter as $filterData) {
$filterData = explode('-', $filterData);
$attributeFilterArray[$filterData[0]][] = $filterData[1];
}
return json_encode($attributeFilterArray);
}
public function setServiceGroupId($id)
{
return $this->serviceGroupId = $id;
}
public function getServiceGroupId()
{
return $this->serviceGroupId;
}
/* Similar Sku */
public function setSimilarSku($similarSku)
{
return $this->similarSku = $similarSku;
}
public function getSimilarSku()
{
return $this->similarSku;
}
/* Similar Sku */
/******************************************Solr call api ends**************************************************/
/******************************************set category filter starts**************************************************/
public function setCategoryFilter($categoryFilter)
{
$categoryFilter = trim($categoryFilter);
if ($categoryFilter) {
$this->categoryFilter = $this->parseCategoryFilterAttribute($categoryFilter);
}
}
private function parseCategoryFilterAttribute($categoryFilter)
{
$categoryFilterArray = array();
$categoryFilter = json_decode($categoryFilter);
return json_encode($categoryFilter);
}
public function setBrandFilter($brandFilter)
{
$brandFilter = trim($brandFilter);
if ($brandFilter) {
$this->brandFilter = $this->parseBrandFilterAttribute($brandFilter);
}
}
private function parseBrandFilterAttribute($brandFilter)
{
$brandFilterArray = array();
$brandFilter = json_decode($brandFilter);
return json_encode($brandFilter);
}
/******************************************set category filter ends**************************************************/
/******************************************set sort starts**************************************************/
public function setSortBy($sortBy)
{
$this->sortBy = trim($sortBy);
if ($this->sortBy) {
$sortBy = explode('::', $this->sortBy);
$this->sortField = $sortBy[0];
$this->sortOrder = strtoupper($sortBy[1]);
}
}
/******************************************set sort ends**************************************************/
/******************************************Feature starts**************************************************/
public function setNewProduct($newProduct)
{
$this->newProduct = ($newProduct)?'yes':'';
}
public function setFeaturedProduct($featuredProduct)
{
$this->featuredProduct = ($featuredProduct)?'yes':'';
}
public function setSaleProductAdd($addSaleProduct)
{
$this->addSale = $addSaleProduct;
}
public function setCloseoutProduct($closeoutProduct)
{
$this->closeoutProduct = ($closeoutProduct)?'yes':'';
}
public function setSaleCloseoutProduct($saleCloseoutProduct)
{
$this->saleCloseoutProduct = ($saleCloseoutProduct)?'yes':'';
}
/******************************************Featured ends**************************************************/
public function setProductPerPage($productPerPage)
{
$this->productPerPage = trim($productPerPage);
}
public function getCountry()
{
return $this->country;
}
public function setCountry($country)
{
$this->country = $country;
return $this;
}
public function getTag()
{
return $this->tag;
}
public function setTag($tag)
{
$this->tag = $tag;
return $this;
}
public function getCategoryId()
{
return $this->categoryId;
}
public function setCategoryId($categoryId)
{
$this->categoryId = $categoryId;
return $this;
}
public function getColorMapping()
{
return $this->colorMapping;
}
public function setColorMapping($colorMapping)
{
$this->colorMapping = $colorMapping;
return $this;
}
public function getSupplierId()
{
return $this->supplierId;
}
public function setSupplierId($supplierId)
{
$this->supplierId = $supplierId;
return $this;
}
public function getBrandId()
{
return $this->brandId;
}
public function setBrandId($brandId)
{
$this->brandId = $brandId;
return $this;
}
public function getMinPrice()
{
return $this->minPrice;
}
public function setMinPrice($minPrice)
{
$this->minPrice = $minPrice;
return $this;
}
public function getMinPriceWithoutLogin()
{
return $this->minPriceWithoutLogin;
}
public function setMinPriceWithoutLogin($minPriceWithoutLogin)
{
$this->minPriceWithoutLogin = $minPriceWithoutLogin;
return $this;
}
public function getMaxPrice()
{
return $this->maxPrice;
}
public function setMaxPrice($maxPrice)
{
$this->maxPrice = $maxPrice;
return $this;
}
public function getMinQty()
{
return $this->minQty;
}
public function setMinQty($minQty)
{
$this->minQty = $minQty;
return $this;
}
public function getMaxQty()
{
return $this->maxQty;
}
public function setMaxQty($maxQty)
{
$this->maxQty = $maxQty;
return $this;
}
public function getPageNumber()
{
return $this->pageNumber;
}
public function setPageNumber($pageNumber)
{
$this->pageNumber = $pageNumber;
return $this;
}
public function getSortOn()
{
return $this->sortOn;
}
public function setSortOn($sortOn)
{
$this->sortOn = $sortOn;
return $this;
}
public function getSortOrder()
{
return $this->sortOrder;
}
public function setSortOrder($sortOrder)
{
$this->sortOrder = $sortOrder;
return $this;
}
public function getKeyword()
{
return $this->keyword;
}
public function setKeyword($keyword)
{
$this->keyword = $keyword;
return $this;
}
public function getAttribute()
{
return $this->attribute;
}
public function setAttribute($attribute)
{
$this->attribute = $attribute;
return $this;
}
public function getSort()
{
return $this->sort;
}
public function setSort($sort)
{
$this->sort = $sort;
return $this;
}
public function getCategorySlug()
{
return $this->categorySlug;
}
public function setCategorySlug($categorySlug)
{
$this->categorySlug = $categorySlug;
return $this;
}
/**
* @param mixed $lineNameId
*/
public function setLineNameId($lineNameId)
{
$this->lineNameId = $lineNameId;
}
/**
* @return mixed
*/
public function getLineNameId()
{
return $this->lineNameId;
}
/**
* @param mixed $searchType
*/
public function setSearchType($searchType)
{
$this->searchType = $searchType;
}
/**
* @return mixed
*/
public function getSearchType()
{
return $this->searchType;
}
/**
* @param mixed $catalogYear
*/
public function setCatalogYear($catalogYear)
{
$this->catalogYear = $catalogYear;
}
/**
* @return mixed
*/
public function getCatalogYear()
{
return $this->catalogYear;
}
/**
* @param mixed $priceValidUntil
*/
public function setPriceValidUntil($priceValidUntil)
{
$this->priceValidUntil = $priceValidUntil;
}
/**
* @return mixed
*/
public function getPriceValidUntil()
{
return $this->priceValidUntil;
}
/**
* @param string $languageCode
*/
public function setLanguageCode($languageCode)
{
$this->languageCode = $languageCode;
}
/**
* @return string
*/
public function getLanguageCode()
{
return $this->languageCode;
}
/**
* @param mixed $priceCurrency
*/
public function setPriceCurrency($priceCurrency)
{
$this->priceCurrency = $priceCurrency;
}
/**
* @return mixed
*/
public function getPriceCurrency()
{
return $this->priceCurrency;
}
/**
* @param mixed $quantity
*/
public function setQuantity($quantity)
{
$this->quantity = $quantity;
}
/**
* @return mixed
*/
public function getQuantity()
{
return $this->quantity;
}
/**
* @param mixed $sku
*/
public function setSku($sku)
{
$this->sku = $sku;
}
/**
* @return mixed
*/
public function getSku()
{
return $this->sku;
}
/**
* @param mixed $callForPrice
*/
public function setCallForPrice($callForPrice)
{
$this->callForPrice = $callForPrice;
}
/**
* @return mixed
*/
public function getCallForPrice()
{
return $this->callForPrice;
}
/**
* @param mixed $lineName
*/
public function setLineName($lineName)
{
$this->lineName = $lineName;
}
/**
* @return mixed
*/
public function getLineName()
{
return $this->lineName;
}
/**
* @param mixed $categoryName
*/
public function setCategoryName($categoryName)
{
$this->categoryName = $categoryName;
}
/**
* @return mixed
*/
public function getCategoryName()
{
return $this->categoryName;
}
/**
* @param mixed $postName
*/
public function setPostName($postName)
{
$this->postName = $postName;
}
/**
* @return mixed
*/
public function getPostName()
{
return $this->postName;
}
/**
* @param mixed $instanceId
*/
public function setInstanceId($instanceId)
{
$this->instanceId = $instanceId;
}
/**
* @return mixed
*/
public function getInstanceId()
{
return $this->instanceId;
}
/**
* @param mixed $supplierName
*/
public function setSupplierName($supplierName)
{
$this->supplierName = $supplierName;
}
/**
* @return mixed
*/
public function getSupplierName()
{
return $this->supplierName;
}
/**
* @param mixed $distributorId
*/
public function setDistributorId($distributorId)
{
$this->distributorId = $distributorId;
}
/**
* @return mixed
*/
public function getDistributorId()
{
return $this->distributorId;
}
/**
* @param mixed $customCategoryId
*/
public function setCustomCategoryId($customCategoryId)
{
$this->customCategoryId = $customCategoryId;
}
/**
* @return mixed
*/
public function getCustomCategoryId()
{
return $this->customCategoryId;
}
/**
* @param mixed $productId
*/
public function setProductId($productId)
{
$this->productId = $productId;
}
/**
* @return mixed
*/
public function getProductId()
{
return $this->productId;
}
/**
* @param mixed $userRole
*/
public function setUserRole($userRole)
{
$this->userRole = $userRole;
}
/**
* @return mixed
*/
public function getUserRole()
{
return $this->userRole;
}
/**
* @param mixed $userId
*/
public function setUserId($userId)
{
$this->userId = $userId;
}
/**
* @return mixed
*/
public function getUserId()
{
return $this->userId;
}
/**
* @param mixed $rating
*/
public function setRating($rating)
{
$this->rating = $rating;
}
/**
* @return mixed
*/
public function getRating()
{
return $this->rating;
}
/**
* @param mixed $rating
*/
public function setSupplier($supplier)
{
$this->supplier = $supplier;
}
/**
* @return mixed
*/
public function getSupplier()
{
return $this->supplier;
}
public function getCategoryIdNot()
{
return $this->categoryIdNot;
}
public function setCategoryIdNot($categoryIdNot)
{
$this->categoryIdNot = $categoryIdNot;
return $this;
}
/**
* @param mixed $productIdNot
*/
public function setProductIdNot($productIdNot)
{
$this->productIdNot = $productIdNot;
}
/**
* @return mixed
*/
public function getProductIdNot()
{
return $this->productIdNot;
}
public function getTagNot()
{
return $this->tagNot;
}
public function setTagNot($tagNot)
{
$this->tagNot = $tagNot;
return $this;
}
}