'y', 'bought' => 'y']; protected $_cart; protected $_userData; protected function _init() { $this->addFilter(['type' => $this->_getType()]); if (Qs_Request::getRequestValue('typeSearch') == 'entireListing') { $this->_filterFields = array_merge( $this->_filterFields, $this->getConfigArray('filterFields'), $this->getConfigArray('formElement')[Obj::TYPE_DEFAULT] ); } parent::_init(); } protected function _filter(Zend_Db_Select $select) { parent::_filter($select); $this->_filterByDate($select); return $this; } protected function _filterByDate(Zend_Db_Select $select) { $select->where('`Classified`.`startDate` <= CURRENT_DATE()'); $select->where('`Classified`.`expirationDate` >= CURRENT_DATE()'); return $this; } protected function _getFromDbSelect($primaryKey) { $select = parent::_getFromDbSelect($primaryKey); $this->_filter($select); return $select; } public function initFromForm(array $data) { if (empty($data['bought'])) { $data['bought'] = 'n'; } if (empty($data['enabled'])) { $data['enabled'] = 'n'; } if (empty($data['type'])) { $data['type'] = $this->_getType(); } $this->initFromFormDateRange($data); return parent::initFromForm($data); } protected function _getType() { return ($type = $this->getConfig('listingType')) ? $type : AbstractObj::TYPE_FOR_SALE; } public function insert(array $data = null) { parent::insert($data); if (!$this->isFreePurchase()) { $adminObj = new AdminObj(); $data = $adminObj->setPrimaryKey($this->getPrimaryKey())->getData(); $itemData = [ 'cartItemType' => CartItemObj::ITEM_TYPE, 'productId' => $this->getPrimaryKey(), 'productCategoryId' => 0, 'title' => $data['typeTitle'], 'description' => '', 'shortDescription' => '', 'quantity' => 1, 'price' => \App_Settings_Obj::get('classifiedPrice'), 'applyShipping' => 'n', 'applyTax' => 'n' ]; $this->_getCart()->addItem($itemData); } return $this; } protected function _getCart() { if (null === $this->_cart) { $this->_cart = new App_ECommerce_Cart_Obj(); $this->_cart->setPrimaryKey($this->_cart->getCartId()); } return $this->_cart; } /** * @return bool */ public function isFreePurchase() { return $this->getUserData('isLoggedIn') && in_array($this->getUserData('companyType'), $this->getConfigArray('freeCompanyTypes')); } public function setUserData($data) { $this->_userData = $data; return $this; } public function getUserData($field = null) { return \Qs_Array::get($this->_userData, $field); } }