Example #1
0
 public function productsAction()
 {
     $ns = new Zend_Session_Namespace();
     $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><shineisp></shineisp>');
     $localeID = $ns->idlang;
     $products = $xml->addChild('products');
     try {
         // Get all the products
         $records = Products::getAll(null, $localeID);
         if (!empty($records)) {
             foreach ($records as $item) {
                 $item['ProductsData'][0]['shortdescription'] = strip_tags($item['ProductsData'][0]['shortdescription']);
                 $item['ProductsData'][0]['description'] = strip_tags($item['ProductsData'][0]['description']);
                 $item['ProductsData'][0]['shortdescription'] = html_entity_decode($item['ProductsData'][0]['shortdescription'], ENT_NOQUOTES, "UTF-8");
                 $item['ProductsData'][0]['description'] = html_entity_decode($item['ProductsData'][0]['description'], ENT_NOQUOTES, "UTF-8");
                 $item['ProductsData'][0]['shortdescription'] = str_replace("&", "", $item['ProductsData'][0]['shortdescription']);
                 $item['ProductsData'][0]['description'] = str_replace("&", "", $item['ProductsData'][0]['description']);
                 $categories = products::get_text_categories($item['categories']);
                 $categories = htmlspecialchars($categories);
                 $product = $products->addChild('product');
                 $product->addAttribute('uuid', $item['uuid']);
                 $product->addAttribute('id', $item['product_id']);
                 $product->addAttribute('inserted_at', !empty($item['inserted_at']) ? strtotime($item['inserted_at']) : null);
                 $product->addAttribute('updated_at', !empty($item['updated_at']) ? strtotime($item['updated_at']) : null);
                 $product->addChild('sku', htmlentities($item['sku']));
                 if (!empty($item['ProductsMedia'][0]['path']) && file_exists(PUBLIC_PATH . $item['ProductsMedia'][0]['path'])) {
                     $product->addChild('image', "http://" . $_SERVER['HTTP_HOST'] . $item['ProductsMedia'][0]['path']);
                 }
                 $product->addChild('name', !empty($item['ProductsData'][0]['name']) ? $item['ProductsData'][0]['name'] : null);
                 $product->addChild('shortdescription', !empty($item['ProductsData'][0]['shortdescription']) ? "<![CDATA[" . $item['ProductsData'][0]['shortdescription'] . "]]>" : null);
                 $product->addChild('description', !empty($item['ProductsData'][0]['description']) ? "<![CDATA[" . $item['ProductsData'][0]['description'] . "]]>" : null);
                 $product->addChild('categories', $categories);
                 $price = $product->addChild('price', Products::getPrice($item['product_id']));
                 $price->addAttribute('taxincluded', 0);
                 $price->addAttribute('isrecurrent', products::isRecurring($item['product_id']));
                 $price->addAttribute('currency', Settings::findbyParam('currency'));
             }
         }
         header('Content-Type: text/xml; charset=utf-8');
         die($xml->asXML());
     } catch (Exception $e) {
         Shineisp_Commons_Utilities::log(__CLASS__ . " " . $e->getMessage());
         die;
     }
 }
Example #2
0
 /**
  * retrieve products by their category name
  *
  * @param string $name          name of the category
  * @param int    $enabledFilter whether to allow enabled/disabled products
  *
  * @return object instance of Products object
  */
 static function getByCategoryName($name, $enabledFilter = 0, $noRecurse = 0)
 {
     $arr = explode('/', $name);
     if ($arr[0] == '') {
         array_shift($arr);
     }
     $cid = 0;
     foreach ($arr as $name) {
         $cid = dbOne('select id from products_categories where parent_id=' . $cid . ' and name="' . addslashes($name) . '" limit 1', 'id', 'products_categories');
         if (!$cid) {
             break;
         }
     }
     if (!$cid) {
         return Products::getAll('', 0, $enabledFilter);
     }
     return Products::getByCategory($cid, array(), '_name', 'asc', 0, $noRecurse);
 }
Example #3
0
 /**
  * Search the record for the Select2 JQuery Object by ajax
  * @return json
  */
 public function searchAction()
 {
     if ($this->getRequest()->isXmlHttpRequest()) {
         $term = $this->getParam('term');
         $id = $this->getParam('id');
         if (!empty($term)) {
             $term = "%{$term}%";
             $records = Products::findbyName($term, "product_id, pd.name as name", true);
             die(json_encode($records));
         }
         if (!empty($id)) {
             $records = Products::find($id);
             die(json_encode($records));
         }
         $records = Products::getAll('product_id, pd.name as name');
         die(json_encode($records));
     } else {
         die;
     }
 }