/**
  * Delete category
  *
  * @param void
  * @return null
  */
 function delete_category()
 {
     if ($this->active_category->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if ($this->request->isSubmitted()) {
         $delete = $this->active_category->delete();
         if ($delete && !is_error($delete)) {
             if ($this->request->getFormat() == FORMAT_HTML) {
                 flash_success('Category :category_name has been deleted', array('category_name' => $this->active_category->getName()));
                 $this->redirectToUrl($this->smarty->get_template_vars('categories_url'));
             } else {
                 $this->serveData($this->active_category, 'category');
             }
             // if
         } else {
             if ($this->request->getFormat() == FORMAT_HTML) {
                 flash_error('Failed to delete :category_name', array('category_name' => $this->active_category->getName()));
                 $this->redirectToUrl($this->smarty->get_template_vars('categories_url'));
             } else {
                 $this->serveData($delete);
             }
             // if
         }
         // if
     } else {
         $this->httpError(HTTP_ERR_BAD_REQUEST);
     }
     // if
 }
Example #2
0
 function test_getName()
 {
     $name = "Work stuff";
     $test_Category = new Category($name);
     $result = $test_Category->getName();
     $this->assertEquals($name, $result);
 }
Example #3
0
 public function index()
 {
     $type = Param::get('type', self::TYPE_THREAD);
     $query = trim_collapse(Param::get('query'));
     $page = Param::get('page', 1);
     $pagination = new SimplePagination($page, self::RESULTS_PERPAGE);
     if (!$query) {
         redirect(APP_URL);
     }
     $results = new stdClass();
     switch ($type) {
         case self::TYPE_THREAD:
             $results = Thread::search($query, $pagination->start_index - 1, $pagination->count + 1);
             // Get other info for each thread
             foreach ($results->result as $thread) {
                 $thread->creator = User::getByID($thread->user_id);
                 $thread->category = Category::getName($thread->category_id);
                 $thread->replies_count = Comment::countAll($thread->id);
             }
             break;
         case self::TYPE_COMMENT:
             $results = Comment::search($query, $pagination->start_index - 1, $pagination->count + 1);
             break;
         case self::TYPE_USER:
             $results = User::search($query, $pagination->start_index - 1, $pagination->count + 1);
             break;
         default:
             throw new PageNotFoundException();
             break;
     }
     $pagination->checkLastPage($results->result);
     $pages = ceil($results->total_result / self::RESULTS_PERPAGE);
     $title = "Search: '{$query}'";
     $this->set(get_defined_vars());
 }
 public static function getAllCategoriesFromDatabase($dbConn)
 {
     $categoryIds = readFromDatabase::readEntireColumnFromTable($dbConn, array(self::ID_COLUMN_NAME), self::TABLE_NAME);
     $categories = array();
     foreach ($categoryIds as $categoryId) {
         $category = new Category($dbConn, $categoryId[self::ID_COLUMN_NAME]);
         $categories[$category->getId()] = $category->getName();
     }
     return $categories;
 }
Example #5
0
 function test_getName()
 {
     //Arrange
     $name = "Work stuff";
     $test_Category = new Category($name);
     //Act
     $result = $test_Category->getName();
     //Assert
     $this->assertEquals($name, $result);
 }
 protected function modify(Category $category)
 {
     $q = $this->dao->prepare('UPDATE ' . $this->table() . ' SET NAME = :name, DESCRIPTION = :description, PARENT_CATEGORY_ID = :parentCategoryId, IS_ROOT = :isRoot WHERE ID = :id');
     $q->bindValue(':name', $category->getName());
     $q->bindValue(':description', $category->getDescription());
     $q->bindValue(':parentCategoryId', $category->getParentCategoryId());
     $q->bindValue(':isRoot', $category->getIsRoot());
     $q->bindValue(':id', $category->id(), PDO::PARAM_INT);
     $q->execute();
 }
Example #7
0
 function action_category()
 {
     if (isset($_GET['id']) && $_GET['id'] > 0) {
         $id = DB::esc(intval($_GET['id']));
         $category = new Category($id, $this->model);
         $this->view->setData(array("category" => $category));
         $this->view->setTitle($category->getName());
         $this->view->display('category_view.php');
     } else {
         $this->action_404();
     }
 }
 public function edit(User $currentUser, Category $category)
 {
     $id = intval($category->getId());
     $name = $this->database->quote($category->getName());
     $description = $this->database->quote($category->getDescription());
     $query = "UPDATE category SET name = '" . $name . "', description = '" . $description . "' WHERE id = " . $id;
     $result = $this->database->exec($query);
     if ($result) {
         return true;
     } else {
         throw new Exception("Catastrophe base de données.");
     }
 }
Example #9
0
 function testUpdate()
 {
     //Arrange
     $name = "Work stuff";
     $id = 1;
     $test_category = new Category($name, $id);
     $test_category->save();
     $new_name = "Home stuff";
     //Act
     $test_category->update($new_name);
     //Assert
     $this->assertEquals("Home stuff", $test_category->getName());
 }
 /**
  * @param Category $category
  * @return WikiaMobileCategoryViewer
  */
 public function getItemsCollection(Category $category)
 {
     $this->wf->profileIn(__METHOD__);
     $cacheKey = $this->getItemsCollectionCacheKey($category->getName());
     $contents = $this->wg->memc->get($cacheKey);
     if (empty($contents)) {
         /**
          * @var $wikiaMobileCategoryViewer WikiaMobileCategoryViewer
          */
         $wikiaMobileCategoryViewer = F::build('WikiaMobileCategoryViewer', array($category));
         $contents = $wikiaMobileCategoryViewer->getContents();
         $this->wg->memc->set($cacheKey, $contents, self::CACHE_TTL_ITEMSCOLLECTION);
     }
     $this->wf->profileOut(__METHOD__);
     return $contents;
 }
 protected function getCategoryArray($id_product)
 {
     /*
     $controlFraude = new TPProductoControlFraude($id_product);
             return $controlFraude->codigo_producto;
     */
     $controlFraude = new Product($id_product);
     $categories = $controlFraude->getDefaultCategory();
     $category_id = $categories[0];
     $category = new Category($category_id);
     $name = $category->getName();
     if (empty($name)) {
         return "default";
     }
     return $name;
 }
 public function create($name, $description, $img)
 {
     $category = new Category($this->db);
     $errors = array();
     try {
         $category->setName($name);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     try {
         $category->setDescription($description);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     try {
         $category->setImg($img);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     if (count($errors) == 0) {
         $name = $this->db->quote($category->getName());
         $description = $this->db->quote($category->getDescription());
         $img = $this->db->quote($category->getImg());
         $query = "INSERT INTO category (name, description, img) VALUES(" . $name . "," . $description . "," . $img . ")";
         $res = $this->db->exec($query);
         if ($res) {
             $id = $this->db->lastInsertId();
             if ($id) {
                 return $this->findById($id);
             } else {
                 $errors[] = "Category not found";
                 return $errors;
             }
         } else {
             $errors[] = "Internal server error";
             return $errors;
         }
     } else {
         return $errors;
     }
 }
 static function findAllCategories()
 {
     $default_category = new Category('default');
     $categories = array();
     foreach (Project::findAllProjects() as $project) {
         if ($name = $project->getCategory()) {
             if (!isset($categories[$name])) {
                 $category = new Category($name);
                 $categories[$name] = $category;
             } else {
                 $category = $categories[$name];
             }
         } else {
             $categories[$default_category->getName()] = $default_category;
             $category = $default_category;
         }
         $category->addProject($project);
     }
     ksort($categories);
     return array_values($categories);
 }
Example #14
0
 public function index()
 {
     $page = Param::get('page', 1);
     $filter = Param::get('filter');
     // pagination
     $pagination = new SimplePagination($page, self::THREADS_PERPAGE);
     $threads = Thread::getAll($pagination->start_index - 1, $pagination->count + 1, $filter);
     $pagination->checkLastPage($threads);
     $total = Thread::countAll($filter);
     $pages = ceil($total / self::THREADS_PERPAGE);
     // Get other info for each thread
     foreach ($threads as $thread) {
         $thread->creator = User::getByID($thread->user_id);
         $thread->category = Category::getName($thread->category_id);
         $thread->replies_count = Comment::countAll($thread->id);
     }
     // get other variables needed by the view
     $title = 'All Threads';
     $auth_user = User::getAuthenticated();
     $categories = Category::getAll();
     $trending = Thread::getTrending(self::TRENDING_LIMIT);
     $this->set(get_defined_vars());
 }
 protected function itemExportCategories($row, $product)
 {
     // Url in 1.5.2.0 wrong (thickbox_default)
     //Categories
     $category = new Category($product->id_category_default);
     $row['categories'] = $category->getName($this->id_lang);
     return $row;
 }
$t->is(count($category), 0, 'findOne() called after select(array) returns an empty array if no record is found');

$category1 = new Category();
$category1->setName('cat1');
$category1->save();
$category2 = new Category();
$category2->setName('cat2');
$category2->save();

$finder = sfPropelFinder::from('Category')->
  select(array('Id','Name'), sfModelFinder::ASSOCIATIVE);
$category = $finder->findOne();
$t->isa_ok($category, 'array', 'The row returned by findOne() called after select(array) is an array');
$t->is_deeply(array_keys($category), array('Id', 'Name'), 'The row returned by findOne() called after select(array, sfModelFinder::ASSOCIATIVE) is an associative array where the keys are the requested column names');
$t->is($category['Id'], $category1->getId(), 'The row returned by findOne() called after select(array, sfModelFinder::ASSOCIATIVE) is an associative array where the values are the requested column values');
$t->is($category['Name'], $category1->getName(), 'The row returned by findOne() called after select(array, sfModelFinder::ASSOCIATIVE) is an associative array where the values are the requested column values');

$finder = sfPropelFinder::from('Category')->
  select(array('Id','Name'), sfModelFinder::SIMPLE);
$category = $finder->findOne();
$t->is_deeply(array_keys($category), array(0, 1), 'The row returned by findOne() called after select(array, sfModelFinder::SIMPLE) is an array with numeric keys');
$t->is($category[0], $category1->getId(), 'The row returned by findOne() called after select(array, sfModelFinder::SIMPLE) is an array where the values are the requested column values');
$t->is($category[1], $category1->getName(), 'The row returned by findOne() called after select(array, sfModelFinder::SIMPLE) is an array where the values are the requested column values');

/*********************************************/
/* sfPropelFinder::select() and withColumn() */
/*********************************************/

$t->diag('sfPropelFinder::select() and withColumn()');

ArticlePeer::doDeleteAll();
Example #17
0
<h3 class="title">查看 图片 #<?php 
echo $model->id;
?>
</h3>

<?php 
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('id', 'title', array('name' => 'pid', 'value' => Category::getName($model->pid)), array('name' => 'img', 'value' => CHtml::link(CHtml::image('http://7xssk6.com2.z0.glb.clouddn.com/' . $model->img, '图片', array('width' => '150px')), 'http://7xssk6.com2.z0.glb.clouddn.com/' . $model->img, array("target" => "_blank")), 'type' => 'raw'), 'des', 'orderid', array('name' => 'is_show', 'value' => $model->is_show == 1 ? "是" : "否"), 'create_at:datetime', array('name' => 'create_uid', 'value' => User::getName($model->create_uid)))));
Example #18
0
function addProducts($client, $ids = array())
{
    //update currency
    // update_currency();
    $default_tz = date_default_timezone_get();
    date_default_timezone_set('UTC');
    $category = new Category(1, 1);
    $sql = "select p.id_product, DATEDIFF(NOW(), p.`date_add`) as 'age'\n            from ps_product p\n            where p.price > 0 and p.active = 1";
    $productScores = array();
    $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
    foreach ($products as $product) {
        $productScores[$product['id_product']] = array('age' => $product['age'], 'week_sold' => 0, 'month_sales' => 0, 'year_sales' => 0);
    }
    $sql = "select p.`id_product`, sum(od.product_quantity) as 'quantity'\n            from `ps_product` p\n            inner join `ps_order_detail` od on od.product_id = p.id_product\n            inner join ps_orders o on o.id_order = od.id_order\n            where p.price > 0 \n            and p.active = 1\n            and o.date_add > now() - INTERVAL 7 DAY\n            group by p.id_product";
    $week_quantities = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
    foreach ($week_quantities as $week_quantity) {
        $productScores[$week_quantity['id_product']]['week_sold'] = $week_quantity['quantity'];
    }
    $sql = "select p.`id_product`, round(sum(od.product_quantity * od.product_price * 55 / o.`conversion_rate`)) as 'month_revenue'\n            from `ps_product` p\n            inner join `ps_order_detail` od on od.product_id = p.id_product\n            inner join ps_orders o on o.id_order = od.id_order\n            where p.price > 0 and p.active = 1\n            and o.date_add > now() - INTERVAL 30 DAY\n            group by p.id_product";
    $month_sales = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
    foreach ($month_sales as $month_sale) {
        $productScores[$month_sale['id_product']]['month_sales'] = $month_sale['month_revenue'];
    }
    $sql = "select p.`id_product`, round(sum(od.product_quantity * od.product_price * 55 / o.`conversion_rate`)) as 'year_revenue'\n            from `ps_product` p\n            inner join `ps_order_detail` od on od.product_id = p.id_product\n            inner join ps_orders o on o.id_order = od.id_order\n            where p.price > 0 and p.active = 1\n            and o.date_add > now() - INTERVAL 365 DAY\n            group by p.id_product";
    $year_sales = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
    foreach ($year_sales as $year_sale) {
        $productScores[$year_sale['id_product']]['year_sales'] = $year_sale['year_revenue'];
    }
    foreach ($products as $product) {
        $productScores[$product['id_product']]['score'] = getWeekSalesScore($productScores[$product['id_product']]['week_sold']) + getAgeScore($productScores[$product['id_product']]['age']) + getMonthScore($productScores[$product['id_product']]['month_sales']) + getYearScore($productScores[$product['id_product']]['year_sales']);
    }
    $docs = array();
    $link = new Link();
    $count = 0;
    $update = $client->createUpdate();
    foreach ($products as $product) {
        if (!empty($ids) && !in_array((int) $product['id_product'], $ids)) {
            continue;
        }
        $productObj = new Product((int) $product['id_product'], true, 1);
        print_r('\\n' . 'reindexing ' . $product['id_product']);
        if (!$productObj->active) {
            deleteProduct($productObj->id, $client);
            continue;
        }
        $doc = $update->createDocument();
        $doc->id_product = $productObj->id;
        $doc->reference = $productObj->reference;
        $doc->name = $productObj->name;
        $doc->description = preg_replace('@[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F]@', ' ', $productObj->description);
        $doc->description_short = preg_replace('@[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F]@', ' ', $productObj->description_short);
        $doc->brand_id = $productObj->id_manufacturer;
        $doc->brand_name = $productObj->manufacturer_name;
        $doc->style_tips = $productObj->description_short;
        $doc->alphaNameSort = $productObj->name;
        $dbresult = $productObj->getWsCategories();
        $catIds = array();
        foreach ($dbresult as $catIdRow) {
            $catIds[] = $catIdRow['id'];
        }
        $category_names = array();
        foreach ($catIds as $catID) {
            $category = new Category((int) $catID);
            $category_names[] = $category->getName(1);
        }
        $doc->cat_name = $category_names;
        $doc->cat_id = $catIds;
        $doc->tags = $productObj->getTags(1);
        $doc->shipping_sla = $productObj->shipping_sla ? $productObj->shipping_sla : 0;
        $doc->weight = $productObj->weight ? $productObj->weight : 0.5;
        if (isset($productObj->work_type)) {
            $doc->work_type = preg_replace('@[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F]@', ' ', $productObj->work_type ? $productObj->work_type : '');
        }
        if (isset($productObj->garment_type)) {
            $doc->garment_type = preg_replace('@[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F]@', ' ', $productObj->garment_type ? $productObj->garment_type : '');
        }
        if (isset($productObj->blouse_length)) {
            $doc->blouse_length = $productObj->blouse_length ? $productObj->blouse_length : '';
        }
        $doc->height = $productObj->height;
        $doc->width = $productObj->width;
        $atributeQty = Attribute::getAttributeQty($productObj->id);
        if ($productObj->quantity > 0 || $atributeQty > 0) {
            $doc->inStock = true;
        } else {
            $doc->inStock = false;
        }
        $doc->isPlusSize = $productObj->is_plussize ? true : false;
        $doc->isRTS = $productObj->is_rts ? true : false;
        $doc->quantity = $productObj->quantity ? $productObj->quantity : ($atributeQty ? $atributeQty : 0);
        //Indian Price
        $doc->offer_price_in = Product::getPriceStatic($productObj->id, true, NULL, 6, NULL, false, true, 1, false, NULL, NULL, IND_ADDRESS_ID);
        $doc->offer_price_in_rs = Tools::convertPrice($doc->offer_price_in, 4);
        $doc->mrp_in = Product::getPriceStatic($productObj->id, true, NULL, 6, NULL, false, false, 1, false, NULL, NULL, IND_ADDRESS_ID);
        if ($doc->mrp_in > $doc->offer_price_in) {
            $doc->discount_in = Tools::ps_round(($doc->mrp_in - $doc->offer_price_in) / $doc->mrp_in * 100);
        }
        //Worldwide Price
        $doc->offer_price = $productObj->getPrice();
        $doc->offer_price_rs = Tools::convertPrice($doc->offer_price, 4);
        $doc->mrp = $productObj->getPriceWithoutReduct();
        if ($doc->mrp > $doc->offer_price) {
            $doc->discount = Tools::ps_round(($doc->mrp - $doc->offer_price) / $doc->mrp * 100);
        }
        $date = DateTime::createFromFormat('Y-m-d H:i:s', $productObj->date_add);
        $doc->date_add = $date->format("Y-m-d\\TG:i:s\\Z");
        $doc->product_link = $productObj->getLink();
        $idImage = $productObj->getCoverWs();
        if ($idImage) {
            $idImage = $productObj->id . '-' . $idImage;
        } else {
            $idImage = Language::getIsoById(1) . '-default';
        }
        $doc->image_link_list = $link->getImageLink($productObj->link_rewrite, $idImage, 'list');
        $doc->image_link_medium = $link->getImageLink($productObj->link_rewrite, $idImage, 'medium');
        $doc->image_link_large = $link->getImageLink($productObj->link_rewrite, $idImage, 'large');
        $images = $productObj->getImages(1);
        $productImages = array();
        foreach ($images as $k => $image) {
            $productImages[] = $link->getImageLink($productObj->link_rewrite, $image['id_image'], 'large');
        }
        $doc->image_links = $productImages;
        $doc->sales = $productScores[$product['id_product']]['score'];
        $productObj->fabric = trim($productObj->fabric);
        $productObj->fabric = preg_replace('/\\s+/', '-', $productObj->fabric);
        $doc->fabric = strtolower($productObj->fabric);
        $doc->is_customizable = $productObj->is_customizable;
        if (isset($productObj->generic_color) && !empty($productObj->generic_color)) {
            $colors = explode(',', $productObj->generic_color);
            $indexed_colors = array();
            foreach ($colors as $color) {
                $indexed_colors[] = strtolower(preg_replace('/\\s+/', '-', trim($color)));
            }
            $doc->color = $indexed_colors;
        }
        if (isset($productObj->stone) && !empty($productObj->stone)) {
            $stones = explode(',', $productObj->stone);
            $indexed_stones = array();
            foreach ($stones as $stone) {
                $indexed_stones[] = strtolower(preg_replace('/\\s+/', '-', trim($stone)));
            }
            $doc->stone = $indexed_stones;
        }
        if (isset($productObj->plating) && !empty($productObj->plating)) {
            $platings = explode(',', $productObj->plating);
            $indexed_platings = array();
            foreach ($platings as $plating) {
                $indexed_platings[] = strtolower(preg_replace('/\\s+/', '-', trim($plating)));
            }
            $doc->plating = $indexed_platings;
        }
        if (isset($productObj->material) && !empty($productObj->material)) {
            $materials = explode(',', $productObj->material);
            $indexed_materials = array();
            foreach ($materials as $material) {
                $indexed_materials[] = strtolower(preg_replace('/\\s+/', '-', trim($material)));
            }
            $doc->material = $indexed_materials;
        }
        if (isset($productObj->look) && !empty($productObj->look)) {
            $looks = explode(',', $productObj->look);
            $indexed_looks = array();
            foreach ($looks as $look) {
                $indexed_looks[] = strtolower(preg_replace('/\\s+/', '-', trim($look)));
            }
            $doc->look = $indexed_looks;
        }
        if (isset($productObj->handbag_occasion) && !empty($productObj->handbag_occasion)) {
            $handbag_occasions = explode(',', $productObj->handbag_occasion);
            $indexed_handbag_occasions = array();
            foreach ($handbag_occasions as $handbag_occasion) {
                $indexed_handbag_occasions[] = strtolower(preg_replace('/\\s+/', '-', trim($handbag_occasion)));
            }
            $doc->handbag_occasion = $indexed_handbag_occasions;
        }
        if (isset($productObj->handbag_style) && !empty($productObj->handbag_style)) {
            $handbag_styles = explode(',', $productObj->handbag_style);
            $indexed_handbag_styles = array();
            foreach ($handbag_styles as $handbag_style) {
                $indexed_handbag_styles[] = strtolower(preg_replace('/\\s+/', '-', trim($handbag_style)));
            }
            $doc->handbag_style = $indexed_handbag_styles;
        }
        if (isset($productObj->handbag_material) && !empty($productObj->handbag_material)) {
            $handbag_materials = explode(',', $productObj->handbag_material);
            $indexed_handbag_materials = array();
            foreach ($handbag_materials as $handbag_material) {
                $indexed_handbag_materials[] = strtolower(preg_replace('/\\s+/', '-', trim($handbag_material)));
            }
            $doc->handbag_material = $indexed_handbag_materials;
        }
        $combinaisons = $productObj->getAttributeCombinaisons(1);
        $indexed_sizes = array();
        foreach ($combinaisons as $k => $combinaison) {
            if ($combinaison['group_name'] == 'size' || $combinaison['group_name'] == 'Size') {
                $indexed_sizes[] = $combinaison['attribute_name'];
            }
        }
        $doc->size = $indexed_sizes;
        $doc->cashback_percentage = $productObj->cashback_percentage;
        $docs[] = $doc;
        if (++$count == 300) {
            $update->addDocuments($docs);
            $result = $client->update($update);
            echo 'Update query executed' . PHP_EOL;
            echo 'Query status: ' . $result->getStatus() . PHP_EOL;
            echo 'Query time: ' . $result->getQueryTime() . PHP_EOL;
            $count = 0;
            $docs = array();
            $update = $client->createUpdate();
        }
    }
    $update->addDocuments($docs);
    date_default_timezone_set($default_tz);
    $result = $client->update($update);
    $sql = "update ps_product set indexed = 1 where indexed = 0";
    Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
}
 $products = array('m' => null, 'c' => null);
 $catalogs = array();
 $ignore_family = false;
 //LOOPING FOR PRODUCTS OF A FAMILY
 //In this loop we validate product and catalog data and
 //rearrange the products in each familiy
 $products_processed_status = array();
 while ($r_catalog = tep_db_fetch_array($dbqcat)) {
     $pid = $r_catalog['products_id'];
     $is_mother = $pid == $family->mother;
     if (!array_key_exists($pid, $products_processed_status)) {
         //Process product data
         $product_errors = array();
         $pdata = $class_pm->retrieveDetail($pid, 'p,pd,pd2,pci,pei,pnc,cat');
         $category = new Category($pdata['categories_id']);
         $category_name = $category->getName($lid);
         $mat_ids = $class_pm->loadProductMaterials($pid);
         $pdata['materials'] = array();
         foreach ($mat_ids as $mat_id) {
             if ($materials_name[$mat_id] != '') {
                 $pdata['materials'][] = $materials_name[$mat_id];
             }
         }
         //MATERIALS CHECK
         if (count($pdata['materials']) == 0) {
             $product_errors[] = 'Product has no Materials';
         }
         //BRAND CHECK
         if ($pdata['p']['products_brand_name'] == '') {
             $product_errors[] = 'Product Brand is not yet set';
         }
 $websites = $product->getWebsiteIds();
 if (!inMainStore($websites)) {
     $websites = implode(",", $websites);
     echo "[wrong website] skip {$id}, websites: {$websites}\n";
     $skippedProducts++;
     continue;
 }
 $data = [];
 $categoryData = [];
 $configProduct = new ConfigurableProduct($product);
 $categories = $configProduct->getCategoryIds();
 $hasActiveCategories = false;
 echo sprintf("(%s) %s %s\n", --$open, str_pad($configProduct->getId(), 5), str_pad($configProduct->getName(), 30));
 foreach ($categories as $categoryId) {
     $category = new Category($categoryId);
     if ($category->isVisible() && strlen($category->getName()) > 0 && !$category->isExcluded()) {
         if ($hasActiveCategories) {
             $categoryData['alternateCategoryId'][] = $categoryId;
             $categoryData['alternateCategoryName'][] = $category->getName();
             $categoryData['alternateCategoryTree'][] = $category->getCategoryTree();
         } else {
             $categoryData['defaultCategoryId'] = $categoryId;
             $categoryData['defaultCategoryName'] = $category->getName();
             $categoryData['defaultCategoryTree'] = $category->getCategoryTree();
             $categoryData['productType'] = $category->getName();
             $categoryData['alternateCategoryId'] = [];
             $categoryData['alternateCategoryName'] = [];
             $categoryData['alternateCategoryTree'] = [];
         }
         $hasActiveCategories = true;
     }
             break;
         }
         if ($this_value !== 'TODO') {
             break;
         }
     }
 }
 $data[] = $this_value;
 //Length
 $data[] = "TODO";
 //Type
 $catIds = $product->getCategories();
 $category_names = array();
 foreach ($catIds as $catID) {
     $category = new Category((int) $catID);
     $category_names[] = $category->getName(1);
 }
 $category_names = array_diff($category_names, array('Home'));
 $categories = implode(',', $category_names);
 $types = array("Daily Wear" => array("daily", "regular", "casual"), "Eveningwear" => array("lounge"), "Regular" => array("casual", "regular", "daily"), "Casual" => array("casual", "work"), "Party Wear" => array("party"));
 $this_value = "TODO";
 foreach ($types as $key => $type_a) {
     foreach ($type_a as $type) {
         if (stripos($categories, $type) !== false) {
             $this_value = $key;
             break;
         }
     }
     if ($this_value !== "TODO") {
         break;
     }
Example #22
0
    Product::initPricesComputation();
    header("Cache-Control: no-store, no-cache");
    header('Content-Encoding: UTF-8');
    header('Content-type: text/csv; charset=UTF-8');
    header('Content-Disposition: attachment; filename="indusdiva-products.csv"');
    $outstream = fopen("php://output", 'w');
    $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS("SELECT id_product from ps_product");
    $header = array('SKU', 'Name', 'Active', 'Price', 'Category', 'MRP', 'Brand');
    fputcsv($outstream, $header, ',', '"');
    foreach ($res as $row) {
        $productDetails = array();
        $id_product = (int) $row['id_product'];
        $product = new Product($id_product, true, 1);
        $price = $product->getPrice();
        $cat = new Category($product->id_category_default);
        $product_category = $cat->getName(1);
        $productDetails = array($product->id, $product->name, $product->active, $product->getPrice(), $product_category, $product->getPriceWithoutReduct(), $product->manufacturer_name);
        fputcsv($outstream, $productDetails, ',', '"');
    }
    fclose($outstream);
}
if (Tools::getValue('getProducts')) {
    $date_from = Tools::getValue('orders_from');
    $date_to = Tools::getValue('orders_to');
    if (!is_array($statusArray = Tools::getValue('id_order_state')) or !count($statusArray)) {
        $statusFilter = '';
    } else {
        $statusFilter = "and os.`id_order_state` in (" . implode(',', $statusArray) . ") ";
    }
    $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS("SELECT SQL_CALC_FOUND_ROWS a.id_order as `order id`, \n    pd.product_name as `Product`, \n    osl.name as `Status`,\n    pd.product_quantity as `Quantity`, \n    round(pp.wholesale_price * 55) as `Souring Price`, \n    pp.ean13 as `EAN`,\n    pp.reference as 'REF',\n    pp.supplier_reference as 'SUP_REF',\n    vl.value as 'Shipping Estimate'\n    FROM `ps_orders` a \n    INNER JOIN `ps_order_detail` pd ON (a.id_order = pd.id_order)\n    INNER JOIN `ps_product` pp ON (pd.product_id = pp.`id_product`)\n    LEFT JOIN `ps_order_history` oh ON (oh.`id_order` = a.`id_order`) \n    LEFT JOIN `ps_order_state` os ON (os.`id_order_state` = oh.`id_order_state`)\n        INNER JOIN `ps_order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state`) \n        INNER JOIN ps_feature_product fp on (fp.id_product = pp.id_product  and fp.id_feature = 8 )\n        INNER JOIN ps_feature_value_lang vl on fp.id_feature_value = vl.id_feature_value\n        LEFT JOIN `ps_currency_rates` pr ON date(pr.`day`) = date(a.`date_add`)\n    WHERE 1 AND oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `ps_order_history` moh WHERE moh.`id_order` = a.`id_order` GROUP BY moh.`id_order`) \n    " . $statusFilter . "\n    and CAST(a.date_add AS DATE) between '" . $date_from . "' and '" . $date_to . "'\n    ORDER BY a.date_add DESC");
    $header = array('Order ID', 'Product', 'Status', 'Quantity', 'Sourcing Price', 'EAN', 'REF', 'SUPPLIER REFERENCE', 'Shipping Estimate');
Example #23
0
<?php

if ($data["category"] != 0) {
    ?>
<div class="category_title">Kategória: <?php 
    $cat = new Category($data["category"]);
    echo $cat->getName();
    ?>
</div>
<script>document.title="Kategória: <?php 
    echo $cat->getName();
    ?>
 - Vitozy Blogja";</script>
<?php 
}
foreach ($data["posts"] as $post) {
    $post_obj = new Post($post["post_id"]);
    ?>
<div class="post">
    <div class="post_header"><?php 
    echo $post["title"];
    ?>
</div>
    <div class="post_content">
        <img src="images/posts/<?php 
    echo $post["indeximage"];
    ?>
">
        <?php 
    echo $post["short_text"];
    ?>
Example #24
0
 public function ajaxCall()
 {
     //sleep(1);
     global $smarty, $cookie;
     $selectedFilters = $this->getSelectedFilters();
     $id_parent = (int) Tools::getValue('id_category', Tools::getValue('id_category_layered', 1));
     $id_manufacturer = Tools::getValue('id_manufacturer', false);
     $sortInfo = '';
     if (Tools::getValue('orderby') && Tools::getValue('orderway')) {
         $sortInfo = Tools::getProductsOrder('by', Tools::getValue('orderby')) . ':' . Tools::getProductsOrder('way', Tools::getValue('orderway'));
     }
     //echo print_r($selectedFilters);
     //$products = $this->getProductByFilters($selectedFilters);
     $resultSet = $this->getResults($id_parent, $this->search_query, $id_manufacturer, $selectedFilters);
     $products = $resultSet->getData();
     $products = $products['response']['docs'];
     $nbProducts = $resultSet->getNumFound();
     $range = 3;
     /* how many pages around page selected */
     $n = (int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE'));
     $p = Tools::getValue('p', 1);
     if ($p < 0) {
         $p = 0;
     }
     if ($p > $nbProducts / $n) {
         $p = ceil($nbProducts / $n);
     }
     $pages_nb = ceil($nbProducts / (int) $n);
     $start = (int) ($p - $range);
     if ($start < 1) {
         $start = 1;
     }
     $stop = (int) ($p + $range);
     if ($stop > $pages_nb) {
         $stop = (int) $pages_nb;
     }
     $smarty->assign('nb_products', $nbProducts);
     $pagination_infos = array('pages_nb' => (int) $pages_nb, 'p' => (int) $p, 'n' => (int) $n, 'range' => (int) $range, 'start' => (int) $start, 'stop' => (int) $stop, 'nArray' => $nArray = (int) Configuration::get('PS_PRODUCTS_PER_PAGE') != 10 ? array((int) Configuration::get('PS_PRODUCTS_PER_PAGE'), 10, 20, 50) : array(10, 20, 50));
     $smarty->assign($pagination_infos);
     $smarty->assign('static_token', Tools::getToken(false));
     $smarty->assign('products', $products);
     $category = new Category((int) $id_parent);
     $selectedCategory = $category->getName(1);
     $productsTitle = $this->search_query ? $this->search_query : ($id_manufacturer ? Manufacturer::getNameById($id_manufacturer, 1) : $selectedCategory);
     $smarty->assign('lazy', 0);
     $nextPage = $p + 1;
     if ($p == $stop) {
         $nextPage = 0;
     }
     $smarty->assign('nextPage', $nextPage);
     $autoLoad = Tools::getValue('al', false);
     header('Content-type: application/json');
     if ($cookie->image_size == IMAGE_SIZE_LARGE) {
         $productListContent = $smarty->fetch(_PS_THEME_DIR_ . 'product-list-page.tpl');
     } else {
         $productListContent = $smarty->fetch(_PS_THEME_DIR_ . 'product-list-page-small.tpl');
     }
     if ($autoLoad) {
         $smarty->assign('autoload', 1);
         return Tools::jsonEncode(array('productList' => $productListContent, 'nextPage' => $nextPage));
     } else {
         $smarty->assign('autoload', 0);
         return Tools::jsonEncode(array('filtersBlock' => $this->generateFiltersBlock($selectedFilters), 'productList' => $productListContent, 'pagination' => $smarty->fetch(_PS_THEME_DIR_ . 'pagination.tpl'), 'totalItems' => $nbProducts, 'sortInfo' => $sortInfo, 'productsTitle' => $productsTitle, 'nextPage' => $nextPage));
     }
     //	return '<div id="layered_ajax_column">'.$this->generateFiltersBlock($selectedFilters).'</div><div id="layered_ajax_products">'.$smarty->fetch(_PS_THEME_DIR_.'product-list.tpl').'</div>';
 }
 function test_update()
 {
     //arrange
     $name = "Business";
     $id = null;
     $test_category = new Category($name, $id);
     $test_category->save();
     $new_name = "Personal";
     //act
     $test_category->update($new_name);
     //assert
     $this->assertEquals("Personal", $test_category->getName());
 }
Example #26
0
<?php

/* @var $this CategoryController */
/* @var $model Category */
$this->breadcrumbs = array('Categories' => array('index'), $model->name);
?>

<h3 class="title">查看 分类 <?php 
echo $model->name;
?>
</h3>

<?php 
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('id', 'name', array('name' => 'pid', 'value' => Category::getName($model->pid)), 'orderid', 'level', 'path', array('name' => 'create_uid', 'value' => User::getName($model->create_uid)), 'create_time', array('name' => 'update_uid', 'value' => User::getName($model->update_uid)), 'update_time')));
Example #27
0
<?php

/* @var $this BlogController */
/* @var $model Blog */
$this->breadcrumbs = array('Blogs' => array('index'), $model->title);
?>
<div class='col-lg-12 page-title'>
<h1 class="title pull-left">查看 博客 <?php 
echo $model->title;
?>
</h1>
<div class="pull-right">
<a class="btn btn-primary" href="<?php 
echo Yii::app()->controller->createUrl('admin');
?>
">返回</a>
<a class="btn btn-primary" href="<?php 
echo Yii::app()->controller->createUrl('update', array('id' => $model->id));
?>
">编辑</a>
</div>
</div>

<div class="col-lg-12">

<?php 
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('id', array('name' => 'pid', 'value' => Category::getName($model->pid)), 'title', 'img', 'brief', array('name' => 'content', 'type' => 'raw'), 'source', array('name' => 'is_show', 'value' => $model->is_show == 1 ? "是" : "否"), 'orderid', 'views', array('name' => 'create_uid', 'value' => User::getName($model->create_uid)), array('name' => 'create_time', 'value' => date('Y-m-d H:i:s', $model->create_time)), 'update_time')));
?>

</div>
$result = $mongo->categories->find();
foreach ($result as $r) {
    $c = new Category();
    $c->setName($r['name']);
    $c->setDescription($r['description']);
    $c->setDisplayPermissionLevel($r['displayPermissionLevel']);
    $c->setPostingPermissionLevel($r['postingPermissionLevel']);
    $g = new CategoryGroup($r['group']['name']);
    $c->setCategoryGroup($g);
    $d = new Department($r['department']['name']);
    $c->setDepartment($d);
    if (!empty($r['customFields'])) {
        $c->setCustomFields(json_encode($r['customFields']));
    }
    $c->save();
    echo "Category: {$c->getName()}\n";
}
// Now that we've got People and Categories in the database,
// Link the Departments with their Categories and Default Person
$result = $mongo->departments->find();
foreach ($result as $r) {
    $d = new Department($r['name']);
    if (!empty($r['defaultPerson']['_id'])) {
        $id = getPersonIdFromCrosswalk($r['defaultPerson']['_id']);
        $d->setDefaultPerson_id($id);
    }
    if (!empty($r['categories'])) {
        $ids = array();
        foreach ($r['categories'] as $c) {
            try {
                $category = new Category($c['name']);
Example #29
0
 /**
  * (non-PHPdoc)
  * @see PartKeepr\Util.Serializable::serialize()
  */
 public function serialize()
 {
     return array("id" => $this->getId(), "name" => $this->getName(), "description" => $this->getDescription(), "comment" => $this->getComment(), "stockLevel" => $this->getStockLevel(), "footprint" => is_object($this->footprint) ? $this->footprint->getId() : null, "minStockLevel" => $this->minStockLevel, "status" => $this->getStatus(), "storageLocation" => is_object($this->storageLocation) ? $this->storageLocation->getId() : null, "category" => is_object($this->category) ? $this->category->getId() : null, "partUnit" => is_object($this->partUnit) ? $this->getPartUnit()->getId() : null, "manufacturers" => $this->serializeChildren($this->getManufacturers()), "distributors" => $this->serializeChildren($this->getDistributors()), "images" => $this->serializeChildren($this->getImages()), "attachments" => $this->serializeChildren($this->getAttachments()), "parameters" => $this->serializeChildren($this->getParameters()), "createDate" => $this->getCreateDate()->format("Y-m-d H:i:s"), "needsReview" => $this->getReviewFlag(), "partCondition" => $this->getCondition(), "internalPartNumber" => $this->getInternalPartNumber(), "categoryName" => is_object($this->category) ? $this->category->getName() : null, "footprintName" => is_object($this->footprint) ? $this->footprint->getName() : null, "storageLocationName" => is_object($this->storageLocation) ? $this->storageLocation->getName() : null);
 }
Example #30
0
 * @copyright 2011 City of Bloomington, Indiana
 * @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
 * @author Cliff Ingham <*****@*****.**>
 */
include '../../../configuration.inc';
include './migrationConfig.inc';
include './categoryTranslation.inc';
$pdo = new PDO(MIGRATION_DSN, MIGRATION_USER, MIGRATION_PASS);
$sql = "select comp_desc from c_types where c_type1!=0";
$result = $pdo->query($sql);
foreach ($result->fetchAll(PDO::FETCH_COLUMN) as $name) {
    $name = trim($name);
    $newName = isset($CATEGORIES[$name]) ? $CATEGORIES[$name] : $name;
    try {
        $category = new Category($newName);
    } catch (Exception $e) {
        $category = new Category();
        $category->setName($newName);
        if (preg_match('/NOTICE/', $name)) {
            list($type, $notice) = explode(' ', $name);
            $type = $type == 'RECYCLING' ? 'RECYCLE' : $type;
            $query = $pdo->prepare('select notice from sanitation_notices where type=?');
            $query->execute(array($type));
            foreach ($query->fetchAll(PDO::FETCH_COLUMN) as $notice) {
                $category->updateProblems($notice);
            }
        }
        $category->save();
        echo $category->getName() . "\n";
    }
}