public function useAction() { 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 ($data = Zend_Json::decode($this->getRequest()->getRawBody())) { if (empty($data['promotion_id'])) { throw new Exception($this->_("An error occurred while saving. Please try again later.")); } $promotion_id = $data['promotion_id']; $promotion = new Promotion_Model_Promotion(); $promotion->find($promotion_id); $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['remove'] = true; throw new Exception($this->_('You have already use this discount')); } else { $promotion_customer->setIsUsed(1)->save(); $html = array("success" => 1, "message" => $this->_("This discount is now used"), "remove" => 1); } } } catch (Exception $e) { $html['error'] = 1; $html['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); } }