public function unlockbyqrcodeAction() { try { $customer_id = $this->getSession()->getCustomerId(); if (!$customer_id) { throw new Exception($this->_('You must be logged in to use a discount')); } if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) { $promotion = new Promotion_Model_Promotion(); $promotion->find(array("unlock_code" => $data["qrcode"], "value_id" => $data["value_id"])); $promotion_id = $promotion->getId(); $promotion_customer = new Promotion_Model_Customer(); $promotion_customer->findLast($promotion_id, $customer_id); if ($promotion->getUnlockCode() != $data["qrcode"]) { throw new Exception($this->_("This code is unrecognized")); } if ($promotion_customer->getIsUsed() != "" && $promotion_customer->getIsUsed() == 0) { throw new Exception($this->_("You have already use this code")); } if (!$promotion_customer->getId()) { $promotion_customer->setPromotionId($promotion_id)->setCustomerId($customer_id); } $promotion_customer->setIsUsed(0)->save(); $html = array("success" => 1); } } catch (Exception $e) { $html = array("error" => 1, "message" => $e->getMessage()); } $this->_sendHtml($html); }
public function validateAction() { try { $customer_id = $this->getSession()->getCustomerId(); if (!$customer_id) { throw new Exception($this->_('You must be logged in to use a discount')); } $html = array(); if ($promotion_id = $this->getRequest()->getPost('promotion_id')) { // Prépare la promotion $promotion = new Promotion_Model_Promotion(); $promotion->find($promotion_id); // Prépare la promotion du client $promotion_customer = new Promotion_Model_Customer(); $promotion_customer->findLast($promotion_id, $customer_id); if (!$promotion_customer->getId()) { $promotion_customer->setPromotionId($promotion_id)->setCustomerId($customer_id); } if ($promotion->getIsUnique() and $promotion_customer->getId() and $promotion_customer->getIsUsed()) { $html['close'] = true; throw new Exception($this->_('You have already use this discount')); } else { $promotion_customer->setIsUsed(1)->save(); $html = array('ok' => true); } } } catch (Exception $e) { $html['error'] = 1; $html['message'] = $e->getMessage(); } $this->_sendHtml($html); }
public function findAction() { if ($value_id = $this->getRequest()->getParam('value_id') and $promotion_id = $this->getRequest()->getParam('promotion_id')) { $option = $this->getCurrentOptionValue(); $promotion = new Promotion_Model_Promotion(); $promotion->find($promotion_id); $data["promotion"] = array("id" => $promotion->getPromotionId(), "picture" => $promotion->getPictureUrl(), "title" => $promotion->getTitle(), "description" => $promotion->getDescription(), "conditions" => $promotion->getConditions(), "is_unique" => (bool) $promotion->getIsUnique(), "end_at" => $promotion->getFormattedEndAt($this->_('MMMM dd y'))); $data["confirm_message"] = $this->_("Do you want to use this coupon?"); $data["social_sharing_is_active"] = $option->getSocialSharingIsActive(); $data["page_title"] = $promotion->getTitle(); $tc = new Application_Model_Tc(); $tc->findByType($this->getApplication()->getId(), "discount"); $text = $tc->getText(); $data["tc_id"] = !empty($text) ? $tc->getId() : null; $this->_sendHtml($data); } }
public function deletepostAction() { $id = $this->getRequest()->getParam("id"); $html = ''; try { $promotion = new Promotion_Model_Promotion(); $promotion->find($id)->delete(); $html = array('promotion_id' => $id, 'success' => 1, 'success_message' => $this->_('Discount successfully deleted'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0); } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'url' => '/promotion/admin/list'); } $this->getLayout()->setHtml(Zend_Json::encode($html)); }
public function deletepostAction() { $id = $this->getRequest()->getParam("id"); $html = ''; try { $promotion = new Promotion_Model_Promotion(); $promotion->find($id); if ($promotion->getUnlockBy() == "qrcode") { $image_name = $promotion->getId() . "-qrpromotion_qrcode.png"; $file = Core_Model_Directory::getBasePathTo("/images/application/" . $this->getApplication()->getId() . "/application/qrpromotion/" . $image_name); if (file_exists($file)) { unlink($file); } } $promotion->delete(); $html = array('promotion_id' => $id, 'success' => 1, 'success_message' => $this->_('Discount successfully deleted'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0); } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'url' => '/promotion/admin/list'); } $this->getLayout()->setHtml(Zend_Json::encode($html)); }
public function __construct($datas = array()) { parent::__construct($datas); $this->_db_table = 'Promotion_Model_Db_Table_Customer'; }