Esempio n. 1
0
 public function getAction()
 {
     $ns = new Zend_Session_Namespace();
     $product = array();
     $uri = $this->getRequest()->getParam('q');
     if (!empty($uri)) {
         $fields = "p.*,pd.productdata_id as productdata_id, \n                           pd.name as name, \n                           pd.shortdescription as shortdescription,\n                           pd.description as description,\n                           pd.metakeywords as metakeywords,\n                           pd.metadescription as metadescription,\n                           pai.*";
         $data = Products::getProductbyUriID($uri, $fields, $ns->langid);
         if (!empty($data) && $data['enabled']) {
             if (!empty($data['blocks'])) {
                 $this->getHelper('layout')->setLayout('2columns-right');
             }
             $this->view->group = Products::GetAttributeGroupByProductID($data['product_id']);
             if (!empty($ns->cart)) {
                 $ns->lastproduct = $uri;
             }
             $refund = false;
             if (is_array($ns->upgrade)) {
                 //Check if the product is OK for upgrade and if OK take refund
                 foreach ($ns->upgrade as $orderid => $upgradeProduct) {
                     if (in_array($data['product_id'], $upgradeProduct)) {
                         $refundInfo = OrdersItems::getRefundInfo($orderid);
                         $refund = $refundInfo['refund'];
                         break;
                     }
                 }
             }
             $form = $this->CreateProductForm();
             $items = ProductsTranches::getList($data['product_id'], $refund);
             // Check the default quantity value
             $term = ProductsTranches::getDefaultItem($data['product_id']);
             if (!empty($term)) {
                 $data['term'] = $term;
             }
             // Check if there are custom terms / billing cycles options
             if (count($items) > 0) {
                 $form->addElement('select', 'term', array('label' => $this->translator->translate('Term'), 'required' => true, 'multiOptions' => $items, 'decorators' => array('Bootstrap'), 'class' => 'form-control input-sm select-billing-cycle'));
                 $form->addElement('hidden', 'quantity', array('value' => '1', 'decorators' => array('ViewHelper')));
             } else {
                 $form->addElement('text', 'quantity', array('label' => $this->translator->translate('Quantity'), 'required' => true, 'value' => '1', 'decorators' => array('Bootstrap'), 'class' => 'form-control input-sm'));
                 $form->addElement('hidden', 'term', array('decorators' => array('ViewHelper')));
             }
             // Adding the product attributes
             $attributes = ProductsAttributesIndexes::getAttributebyProductID($data['product_id'], $ns->langid);
             if (count($attributes) > 0) {
                 $this->view->placeholder("features")->append($this->view->partial('partials/attributes.phtml', array('attributes' => $attributes)));
             }
             $layout = $this->getHelper('layout')->getLayout();
             // Adding the related products
             $related = ProductsRelated::get_products($data['product_id'], $ns->langid);
             if (count($related) > 0) {
                 if ($layout == "1column") {
                     $placeholder = $this->view->placeholder("right");
                     $this->getHelper('layout')->setLayout('2columns-right');
                 } else {
                     list($columns, $sidebar) = explode("-", $layout);
                     $placeholder = $this->view->placeholder($sidebar);
                 }
                 $placeholder->append($this->view->partial('products/related.phtml', array('products' => $related)));
             }
             // Attaching the WIKI Pages
             $wikipages = Wikilinks::getWikiPages($data['product_id'], "products", $ns->langid);
             if (count($wikipages) > 0) {
                 if ($layout == "1column") {
                     $placeholder = $this->view->placeholder("right");
                     $this->getHelper('layout')->setLayout('2columns-right');
                 } else {
                     list($columns, $sidebar) = explode("-", $layout);
                     $placeholder = $this->view->placeholder($sidebar);
                 }
                 $placeholder->append($this->view->partial('products/wikipages.phtml', array('wikipages' => $wikipages)));
             }
             $this->view->reviewsdata = Reviews::getbyProductId($data['product_id']);
             // Set the Metatag information
             $this->view->headTitle()->prepend($data['name']);
             if (!empty($data['metakeywords'])) {
                 $this->view->headMeta()->setName('keywords', $data['metakeywords']);
             }
             if (!empty($data['metadescription'])) {
                 $this->view->headMeta()->setName('description', $data['metadescription']);
             }
             // Send the variables to the view
             $this->view->headertitle = $data['name'];
             $this->view->product = $data;
             $this->view->prices = Products::getPrices($data['product_id'], $refund);
             $this->view->form = $form;
             $form->populate($data);
         } else {
             // Check if there is an url rewrite redirection
             $newuri = UrlRewrite::getTarget($uri);
             if ($newuri) {
                 header("HTTP/1.1 301 Moved Permanently");
                 header("Location: {$newuri}");
                 die;
             } else {
                 return $this->_helper->redirector('index', 'notfound', 'default', array('uri' => $uri));
             }
         }
     } else {
         return $this->_helper->redirector('index', 'index', 'default', array('mex' => 'The request is not correct.', 'status' => 'danger'));
     }
     $this->_helper->viewRenderer('details');
 }