User: John Kagga Date: 8/1/2015 Time: 9:46 AM
Exemplo n.º 1
0
 /**
  * The setter of the field product_id.
  * @param Product $product - the product related to the issue
  */
 public function setProduct(Product $product)
 {
     if ($product == NULL) {
         throw new InvalidArgumentException('[Model\\Issue] Invalid Model\\Product.');
     }
     $this->product_id = $product->getProductId();
 }
Exemplo n.º 2
0
 function productMultiDialog($productId = 0)
 {
     $chooseProduct = new Product($productId);
     $product = new Product();
     $dis['searchKey'] = "";
     $dis['searchProductCat'] = "";
     $dis['searchProductCatId'] = "";
     if ($_SERVER['REQUEST_METHOD'] == "POST") {
         $searchKey = $this->input->post('searchName');
         $searchProductCat = $this->input->post('searchProductCat');
         $searchProductCatId = $this->input->post('searchProductCatId');
         $product->like("name", $searchKey);
         if ($searchProductCatId != "") {
             $product->where_related_productcat('id', $searchProductCatId);
         }
         $dis['searchKey'] = $searchKey;
         $dis['searchProductCat'] = $searchProductCat;
         $dis['searchProductCatId'] = $searchProductCatId;
         $dis['isSearch'] = true;
     }
     if ($productId != 0 && $chooseProduct->accessory->result_count() > 0) {
         $product->where_not_in('id', $chooseProduct->accessory);
     }
     $product->order_by("name", "asc");
     $product->get_iterated(100);
     $dis['chooseProduct'] = $chooseProduct;
     $dis['base_url'] = base_url();
     $dis['product'] = $product;
     $this->load->view("admin/layout/dialogContent/productMultiSelectDialogContent", $dis);
 }
Exemplo n.º 3
0
 public function __construct($controller, $name)
 {
     $product = new Product();
     $title = new TextField('Title', _t('Product.PAGETITLE', 'Product Title'));
     $urlSegment = new TextField('URLSegment', 'URL Segment');
     $menuTitle = new TextField('MenuTitle', 'Navigation Title');
     $sku = TextField::create('InternalItemID', _t('Product.CODE', 'Product Code/SKU'), '', 30);
     $categories = DropdownField::create('ParentID', _t("Product.CATEGORY", "Category"), $product->categoryoptions())->setDescription(_t("Product.CATEGORYDESCRIPTION", "This is the parent page or default category."));
     $otherCategories = ListBoxField::create('ProductCategories', _t("Product.ADDITIONALCATEGORIES", "Additional Categories"), ProductCategory::get()->filter("ID:not", $product->getAncestors()->map('ID', 'ID'))->map('ID', 'NestedTitle')->toArray())->setMultiple(true);
     $model = TextField::create('Model', _t('Product.MODEL', 'Model'), '', 30);
     $featured = CheckboxField::create('Featured', _t('Product.FEATURED', 'Featured Product'));
     $allow_purchase = CheckboxField::create('AllowPurchase', _t('Product.ALLOWPURCHASE', 'Allow product to be purchased'), 1, 'Content');
     $price = TextField::create('BasePrice', _t('Product.PRICE', 'Price'))->setDescription(_t('Product.PRICEDESC', "Base price to sell this product at."))->setMaxLength(12);
     $image = UploadField::create('Image', _t('Product.IMAGE', 'Product Image'));
     $content = new HtmlEditorField('Content', 'Content');
     $fields = new FieldList();
     $fields->add($title);
     //$fields->add($urlSegment);
     //$fields->add($menuTitle);
     //$fields->add($sku);
     $fields->add($categories);
     //$fields->add($otherCategories);
     $fields->add($model);
     $fields->add($featured);
     $fields->add($allow_purchase);
     $fields->add($price);
     $fields->add($image);
     $fields->add($content);
     //$fields = $product->getFrontEndFields();
     $actions = new FieldList(new FormAction('submit', _t("ChefProductForm.ADDPRODUCT", 'Add product')));
     $requiredFields = new RequiredFields(array('Title', 'Model', 'Price'));
     parent::__construct($controller, $name, $fields, $actions, $requiredFields);
 }
Exemplo n.º 4
0
 public function setProduct(Product $product)
 {
     if ($product) {
         $this->api()->addProduct($product->get());
     }
     return $this;
 }
Exemplo n.º 5
0
 private static function getProductGroupsFilter(Product $product)
 {
     $filter = new ARSelectFilter();
     $filter->setOrder(new ARFieldHandle(__CLASS__, "position"), 'ASC');
     $filter->setCondition(new EqualsCond(new ARFieldHandle(__CLASS__, "productID"), $product->getID()));
     return $filter;
 }
Exemplo n.º 6
0
 public function run()
 {
     if (!$this->product) {
         return;
     }
     $this->render($this->view, ['dataProvider' => $this->product->getLinkedProductsDataProvider($this->code)]);
 }
Exemplo n.º 7
0
 /**
  * @covers QueueController::Add
  * @todo Implement testAdd().
  */
 public function testAdd()
 {
     $person = Person::factory('adult');
     $person->name = 'Poehavshiy';
     $person->add();
     $store = Store::factory('Grocery');
     $store->name = 'Prison';
     $store->add();
     $product = new Product();
     $product->name = 'Sladkiy hleb';
     $product->add();
     $request = Application::getInstance()->request;
     $request->setParams(array('storeId' => $store->id, 'personId' => $person->id, 'product_' . $product->id => 'on'));
     $personId = $request->p('personId');
     $storeId = $request->p('storeId');
     $store = Store::get($storeId);
     $person = Person::get($personId);
     $store->queue->add($person);
     $person->basket->drop();
     $name = 'product_' . $product->id;
     $value = $product;
     if (preg_match_all('/^product_(\\d+)$/', $name, $matches)) {
         $person->basket->add(Product::get($matches[1][0]));
     }
 }
Exemplo n.º 8
0
 public function getAdminInterface()
 {
     $st = "select ecomm_product.id as product_id, ecomm_product.name as product_name,\n\t\t\t\tecomm_product.supplier as supplier_id, ecomm_supplier.name as supplier_name, ecomm_product.price as product_price\n\t\t\t\tfrom ecomm_product left join ecomm_supplier on ecomm_product.supplier = ecomm_supplier.id\n\t\t\t\torder by ecomm_supplier.name,ecomm_product.name";
     $products = Database::singleton()->query_fetch_all($st);
     $formPath = "/admin/EComm&section=Plugins&page=ChangeProductPrice";
     $form = new Form('change_product_prices', 'post', $formPath);
     if ($form->validate() && isset($_REQUEST['submit'])) {
         foreach ($products as $product) {
             $ECommProduct = new Product($product['product_id']);
             $ECommProduct->setPrice($_REQUEST['product_' . $product['product_id']]);
             $ECommProduct->save();
         }
         return "Your products' prices have been changed successfully<br/><a href='{$formPath}'>Go back</a>";
     }
     $oldSupplier = 0;
     $currentSupplier = 0;
     $defaultValue = array();
     foreach ($products as $product) {
         $currentSupplier = $product['supplier_id'];
         if ($oldSupplier != $currentSupplier) {
             $form->addElement('html', '<br/><br/><hr/><h3>Supplier: ' . $product['supplier_name'] . '</h3>');
         }
         $form->addElement('text', 'product_' . $product['product_id'], $product['product_name']);
         $defaultValue['product_' . $product['product_id']] = $product['product_price'];
         $oldSupplier = $product['supplier_id'];
     }
     $form->addElement('submit', 'submit', 'Submit');
     $form->setDefaults($defaultValue);
     return $form->display();
 }
Exemplo n.º 9
0
 public function dataAction()
 {
     $w = 80;
     $h = 100;
     $img = $this->_getParam('img');
     $ar_img = split('\\.', $img);
     //print_r($ar_img);exit;
     $Product = new Product();
     $product = $Product->get($ar_img[0]);
     if ($product && $product['picture']) {
         $res = GetWebPage($product['picture'], $RetStatus);
         //header('Content-type: image/jpg');
         //print_r($res);exit;
         //$ar = getimagesizefromstring($res);
         $im = imagecreatefromstring($res);
         $width = imagesx($im);
         $height = imagesy($im);
         //print_r($width." ".$height);
         if ($width > $height) {
             $new_height = $w * $height / $width;
             $new_width = $w;
         } else {
             $new_height = $h;
             $new_width = $h * $width / $height;
         }
         $im_new = imagecreatetruecolor($new_width, $new_height);
         //imagecopyresized($im_new,$im,0, 0, 0, 0, $new_width, $new_height, $width, $height);
         imagecopyresampled($im_new, $im, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
         header('Content-type: image/jpg');
         imagejpeg($im_new);
     }
     $this->_helper->viewRenderer->setNoRender();
     $this->_helper->layout->disableLayout();
 }
 public function run()
 {
     $this->init();
     $this->preProcess();
     global $cookie, $link;
     $id_product = Tools::getValue('id');
     $product = new Product($id_product, true, 1);
     $id_customer = (isset(self::$cookie->id_customer) and self::$cookie->id_customer) ? (int) self::$cookie->id_customer : 0;
     if ($id_customer) {
         $sql = "select id from ps_wishlist where id_customer = " . $id_customer . " and id_product = " . $product->id;
         $res = Db::getInstance()->ExecuteS($sql);
         if ($res) {
             self::$smarty->assign("in_wishlist", true);
         } else {
             self::$smarty->assign("in_wishlist", false);
         }
     } else {
         self::$smarty->assign("in_wishlist", false);
     }
     $idImage = $product->getCoverWs();
     if ($idImage) {
         $idImage = $productObj->id . '-' . $idImage;
     } else {
         $idImage = Language::getIsoById(1) . '-default';
     }
     $image_link = $link->getImageLink($productObj->link_rewrite, $idImage, 'thickbox');
     self::$smarty->assign('product', $product);
     self::$smarty->assign('imagelink', $image_link);
     self::$smarty->assign('productlink', $product->getLink());
     die(self::$smarty->display(_PS_THEME_DIR_ . 'quick-view.tpl'));
 }
Exemplo n.º 11
0
 /**
  * Save log message
  *
  * @param int $action
  * @param Product $product
  * @param int $type
  * @param string $message
  * @param null|string $code
  * @return int|false
  */
 protected static function log($action, Product $product, $type, $message, $code = null)
 {
     $message = trim($message);
     $template = $product->getTemplate();
     $data = array('product_id' => $product->id, 'template_id' => $product->template_id, 'product_name' => $product->original_title, 'template_name' => $template ? $template->name : '-', 'message' => $message, 'code' => $code, 'action' => $action, 'type' => $type, 'datetime' => time());
     return db_query('INSERT INTO ?:ebay_product_log ?e', $data);
 }
Exemplo n.º 12
0
 public static function create(Customer $cus, Product $prd, $opts)
 {
     $material = $opts['material'];
     $order_sn = self::makeOrderSn();
     Pdb::insert(array_merge($opts, array('order_no' => $order_sn, 'customer' => $cus->id, 'product' => $prd->id, 'state' => 'InCart', 'estimate_price' => $prd->estimatePrice(compact('material')), 'add_cart_time=NOW()' => null)), self::$table);
     return new self(Pdb::lastInsertId());
 }
 /**
  * Creates a scheduling in the database.
  *
  * @return Response
  */
 public function create()
 {
     $request = $this->request;
     $scheduling = new Product();
     $scheduling->assign(['end_period' => $request->get('end_period', 'string'), 'period_type_id' => $request->get('period_type_id', 'strint')]);
     return $this->response($request, $scheduling, true);
 }
Exemplo n.º 14
0
 function search()
 {
     $viewMode = $this->uri->segment(2, "") == "" ? "ma-tran" : $this->uri->segment(2);
     $orderBy = $this->uri->segment(3, "") == "" ? "moi-nhat" : $this->uri->segment(3);
     $page = $this->uri->segment(4, "") == "" ? "trang-1" : $this->uri->segment(4);
     if ($_SERVER['REQUEST_METHOD'] == "POST") {
         $searchKey = $this->input->post('searchKey');
         $this->session->set_userdata('searchKey', $searchKey);
     }
     $searchKey = $this->session->userdata('searchkey');
     $limit = $viewMode == "ma-tran" ? 15 : 10;
     $offset = ($this->getPageNumber($page) - 1) * $limit;
     $product = new Product();
     if (trim($searchKey) != "") {
         $product->like('name', $searchKey);
     }
     $product->where('active', 1);
     $product->order_by($this->getOrderBy($orderBy), $this->getOrderDirection($orderBy));
     $product->get_paged_iterated();
     $dis['product'] = $product;
     $dis['pageUrl'] = "tim-kiem";
     $config['base_url'] = site_url($url . "/" . $viewMode . "/" . $orderBy . "/trang-");
     $config['total_rows'] = $product->paged->total_rows;
     $config['per_page'] = $limit;
     $config['use_page_numbers'] = TRUE;
     $config['uri_segment'] = 4;
     $config['num_links'] = 3;
     $config['full_tag_open'] = '<span class="pagin">';
     $config['full_tag_close'] = "</span>";
     $config['first_link'] = FALSE;
     $config['first_tag_open'] = '';
     $config['first_tag_close'] = '';
     $config['last_link'] = FALSE;
     $config['last_tag_open'] = '';
     $config['last_tag_close'] = '';
     $config['next_link'] = '<img src="' . base_url() . 'images/pagination_next.png" />';
     $config['next_tag_open'] = '';
     $config['next_tag_close'] = '';
     $config['prev_link'] = '<img src="' . base_url() . 'images/pagination_pre.png" /';
     $config['prev_tag_open'] = '';
     $config['prev_tag_close'] = '';
     $config['num_tag_open'] = '';
     $config['num_tag_close'] = '';
     $config['cur_tag_open'] = '<span class="active">';
     $config['cur_tag_close'] = '</span>';
     $this->pagination->initialize($config);
     if ($viewMode == 'ma-tran') {
         $dis['view'] = 'product/product_grid';
     } else {
         $dis['view'] = 'product/product_list';
     }
     $productSaleOff = new product();
     $productSaleOff->where('active', 1);
     $productSaleOff->where('isSale', 1);
     $productSaleOff->order_by('id', 'desc');
     $productSaleOff->get_iterated(15);
     $dis['productSaleOff'] = $productSaleOff;
     $dis['base_url'] = base_url();
     $this->viewfront($dis);
 }
Exemplo n.º 15
0
 public function indexAction()
 {
     $categories = new Category();
     //$this->view->categories = array ('1','2','3','4');
     //$this->view->categories = $categories->fetchAll();
     //$this->_helper->actionStack('detail-list');
     //$this->_forward('detail-list');
     //$this->rrr();
     $front = Zend_Controller_Front::getInstance();
     if ($front->getRequest()->getParam('controller') == 'toy') {
         $toy_id = $front->getRequest()->getParam('toy_id');
         $Product = new Product();
         $toy = $Product->get($toy_id);
         $cat_id = $toy['categoryId'];
         $this->view->current_id = $cat_id;
         $this->view->p_type = 'toy';
     } else {
         $cat_id = $front->getRequest()->getParam('cat_id');
         $cat_id = $cat_id ? $cat_id : 0;
         $this->view->current_id = $cat_id;
         $this->view->p_type = 'category';
     }
     //print_r($cat_id);exit;
     $this->view->categories = $categories->get_sort_categories($cat_id);
 }
function _product_link($fk_product)
{
    global $db, $langs, $conf;
    $p = new Product($db);
    $p->fetch($fk_product);
    return $p->getNomUrl(1) . ' ' . $p->label;
}
Exemplo n.º 17
0
 public function __construct(Product $product, $prices = null, LiveCart $application)
 {
     $this->product = $product;
     $this->application = $application;
     if (is_null($prices) && $product->getID()) {
         $prices = $product->getRelatedRecordSet("ProductPrice", new ARSelectFilter());
     }
     if ($prices instanceof ARSet) {
         foreach ($prices as $price) {
             $this->setPrice($price);
         }
     } else {
         if (is_array($prices)) {
             foreach ($prices as $id => $price) {
                 if (array_key_exists('ID', $price)) {
                     $this->prices[$id] = ProductPrice::getInstance($product, Currency::getInstanceById($id));
                 } else {
                     $this->prices[$id] = ProductPrice::getNewInstance($product, Currency::getInstanceById($id));
                 }
                 $this->prices[$id]->price->set($price['price']);
                 $this->prices[$id]->listPrice->set($price['listPrice']);
                 $this->prices[$id]->serializedRules->set(serialize($price['serializedRules']));
                 $this->prices[$id]->resetModifiedStatus();
             }
         }
     }
 }
Exemplo n.º 18
0
 public function createAction()
 {
     if (isset($_POST['ajax']) && isset($_POST['getproducts'])) {
         $productModel = new Product();
         $campaign_id = AF::get($_POST, 'campaign_id', 0);
         $products = $productModel->getCampaignProducts($campaign_id);
         AF::setJsonHeaders('json');
         Message::echoJsonSuccess(array('message' => $products));
     }
     $model = new CampaignProduct();
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['model']) && $_POST['model'] == 'Campprod') {
         $model->fillFromArray($_POST);
         //$model->upsell_id="NULL:sql";
         //$model->user_id_created = $this->user->user_id;
         //$model->user_id_updated = $this->user->user_id;
         //$model->updated = 'NOW():sql';
         //$model->created = 'NOW():sql';
         //$model->model_uset_id = $this->user->user_id;
         if (isset($_POST['ajax'])) {
             if ($model->save()) {
                 $link = AF::link(array('campprod' => 'view'), array('campaign_id' => $model->campaign_id));
                 Message::echoJson('success', array('redirect' => $link));
             } else {
                 Message::echoJsonError(__('campprod_not_created') . ' ' . $model->errors2string);
             }
             die;
         }
         $model->save();
         $this->redirect();
     }
     $this->addToPageTitle('Create Campaign Product');
     $this->render('create', array('model' => $model));
 }
 /**
  * Transforms an object (product) to a int (id).
  *
  * @param  Product|null $entity
  * @return string
  */
 public function transform($entity)
 {
     if (null === $entity) {
         return "";
     }
     return $entity->getId();
 }
Exemplo n.º 20
0
 public function add(Product $p)
 {
     if (isset($this->products[$p->getUniqueProductID()])) {
         throw new \Exception("Product Unique ID already exist, no duplicated products please!");
     }
     $this->products[$p->getUniqueProductID()] = $p;
 }
Exemplo n.º 21
0
 public function actionUpload_product()
 {
     if (Yii::$app->request->isAjax) {
         $model = new ProductCategory();
         $Product = new Product();
         $ProductImageRel = new ProductImageRel();
         $ProductCategoryRel = new ProductCategoryRel();
         $model_cat_title = UploadedFile::getInstance($model, 'cat_title');
         $time = time();
         $model_cat_title->saveAs('product_uploads/' . $time . $model_cat_title->baseName . '.' . $model_cat_title->extension);
         if ($model_cat_title) {
             $response = [];
             $Product->title = $_POST['title'];
             $Product->desc = $_POST['desc'];
             $Product->status = 1;
             if ($Product->save()) {
                 $ProductCategoryRel->category_id = $_POST['id'];
                 $ProductCategoryRel->product_id = $Product->id;
                 $ProductImageRel->product_id = $Product->id;
                 $ProductImageRel->image = $time . $model_cat_title->baseName . '.' . $model_cat_title->extension;
                 if ($ProductCategoryRel->save() && $ProductImageRel->save()) {
                     $response['files'][] = ['name' => $time . $model_cat_title->name, 'type' => $model_cat_title->type, 'size' => $model_cat_title->size, 'url' => Url::base() . '/product_uploads/' . $time . $model_cat_title->baseName . '.' . $model_cat_title->extension, 'deleteUrl' => Url::to(['delete_uploaded_file', 'file' => $model_cat_title->baseName . '.' . $model_cat_title->extension]), 'deleteType' => 'DELETE'];
                     $response['base'] = $time . $model_cat_title->baseName;
                     $response['view'] = $this->renderAjax('uploaded_product', ['url' => Url::base() . '/product_uploads/' . $time . $model_cat_title->baseName . '.' . $model_cat_title->extension, 'basename' => $time . $model_cat_title->baseName, 'id' => $ProductImageRel->id, 'model' => $Product]);
                 }
             } else {
                 $response['errors'] = $product->getErrors();
             }
             return json_encode($response);
         }
     }
 }
Exemplo n.º 22
0
    /**
     * Lists of items
     * @param int $iIdLang
     * @param bool $active
     * @return array
     */
    public static function getProductsCollection($iIdLang = null, $bActive = true)
    {
        if (!Validate::isBool($bActive)) {
            die(Tools::displayError());
        }
        if (is_null($iIdLang)) {
            $iIdLang = (int) Context::getContext()->language->id;
        }
        $sSQL = '
			SELECT r.`id_product`
			FROM `' . _DB_PREFIX_ . 'now_mea_home` r
			' . Shop::addSqlAssociation('now_mea_home', 'r') . '
			LEFT JOIN `' . _DB_PREFIX_ . 'now_product_type_product` pt ON (pt.`id_product` = r.`id_product`)
			WHERE 1 ' . ($bActive ? ' AND r.`active` = 1 ' : '') . '
			AND pt.`id_now_product_type_product` IS NULL
			ORDER BY RAND() LIMIT 0 , ' . Configuration::get('NOW_MEA_HOME_NB_PRODUCT');
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sSQL);
        $aProducts = array();
        foreach ($result as $row) {
            $oProduct = new Product($row['id_product'], false, $iIdLang);
            $oProduct->loadStockData();
            $aProducts[] = $oProduct;
        }
        return $aProducts;
    }
 public function test_updateTimestamps()
 {
     $product = new Product();
     $product->updateTimestamps();
     $this->assertEqual(strlen($product->getCreated()), 19, 'created');
     $this->assertEqual(strlen($product->getUpdated()), 19, 'updated');
 }
Exemplo n.º 24
0
 public function add($product_id, $shipping_id, $order_id, $flags = '')
 {
     //$i = count($this->orderProducts) + 1;
     $this->orderProducts[$product_id] = new OrderProduct();
     $this->orderProducts[$product_id]->allFields = true;
     $this->orderProducts[$product_id]->product_id = $product_id;
     $this->orderProducts[$product_id]->shipping_id = $shipping_id;
     $this->orderProducts[$product_id]->order_id = $order_id;
     $this->orderProducts[$product_id]->flags = $flags;
     $p = new Product();
     $p->fillFromDbPk($product_id);
     $this->orderProducts[$product_id]->product_name = $p->product_name;
     $this->orderProducts[$product_id]->product_sku = $p->product_sku;
     $this->orderProducts[$product_id]->product_price = $p->product_price;
     // do we need to set recurring billing?
     if ($p->subscription_days) {
         $d = new DateTime();
         $interval = 'P' . $p->subscription_days . 'D';
         $d->add(new DateInterval($interval));
         // P1D means a period of 1 day
         $this->orderProducts[$product_id]->recurring_next = $d->format('Y-m-d 00:00:00');
         $this->orderProducts[$product_id]->addFlags('recurring');
         unset($d);
     }
     unset($p);
     $this->updateTotal();
     $this->num_products++;
 }
Exemplo n.º 25
0
 public function loadFromRawData($data, $reset = false)
 {
     if ($reset) {
         $this->initValues();
     }
     $excluded_properties = array('product', 'developer', 'organization');
     foreach (array_keys($data) as $property) {
         if (in_array($property, $excluded_properties)) {
             continue;
         }
         // form the setter method name to invoke setXxxx
         $setter_method = 'set' . ucfirst($property);
         if (method_exists($this, $setter_method)) {
             $this->{$setter_method}($data[$property]);
         } else {
             self::$logger->notice('No setter method was found for property "' . $property . '"');
         }
     }
     if (isset($data['organization'])) {
         $organization = new Organization($this->config);
         $organization->loadFromRawData($data['organization']);
         $this->organization = $organization;
     }
     if (isset($data['product'])) {
         $product = new Product($this->config);
         $product->loadFromRawData($data['product']);
         $this->products[] = $product;
     }
     if (isset($data['developer'])) {
         $developer = new Developer($this->config);
         $developer->loadFromRawData($data['developer']);
         $this->developer = $developer;
     }
 }
    function formObjectOptions($parameters, &$object, &$action, $hookmanager)
    {
        global $conf, $langs, $db;
        if ((in_array('ordercard', explode(':', $parameters['context'])) || in_array('propalcard', explode(':', $parameters['context']))) && $conf->global->REMISE_USE_WEIGHT) {
            print '<script type="text/javascript">
	                $(document).ready(function() { ';
            foreach ($object->lines as &$line) {
                if ($line->fk_product_type == 0 && $line->fk_product > 0) {
                    dol_include_once('/product/class/product.class.php', 'Product');
                    $p = new Product($db);
                    $p->fetch($line->fk_product);
                    if ($p->id > 0) {
                        $weight_kg = $p->weight * $line->qty * pow(10, $p->weight_units);
                        $id_line = !empty($line->id) ? $line->id : $line->rowid;
                        if (!empty($weight_kg)) {
                            print '$("tr#row-' . $id_line . ' td:first").append(" - ' . $langs->trans('Weight') . ' : ' . $weight_kg . 'Kg");';
                        }
                    }
                }
            }
            print '});
	        </script>';
        }
        return 0;
    }
Exemplo n.º 27
0
function textRecord(Product $product, Cart $cart)
{
    global $errors;
    if (!($fieldIds = $product->getCustomizationFieldIds())) {
        return false;
    }
    $authorizedTextFields = array();
    foreach ($fieldIds as $fieldId) {
        if ($fieldId['type'] == _CUSTOMIZE_TEXTFIELD_) {
            $authorizedTextFields[intval($fieldId['id_customization_field'])] = 'textField' . intval($fieldId['id_customization_field']);
        }
    }
    $indexes = array_flip($authorizedTextFields);
    foreach ($_POST as $fieldName => $value) {
        if (in_array($fieldName, $authorizedTextFields) and !empty($value)) {
            if (!Validate::isMessage($value)) {
                $errors[] = Tools::displayError('Invalid message');
            } else {
                $cart->addTextFieldToProduct(intval($product->id), $indexes[$fieldName], $value);
            }
        } elseif (in_array($fieldName, $authorizedTextFields) and empty($value)) {
            $cart->deleteTextFieldFromProduct(intval($product->id), $indexes[$fieldName]);
        }
    }
}
 public function processFeatures()
 {
     if (!Feature::isFeatureActive()) {
         return;
     }
     if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) {
         // delete all objects
         $product->deleteFeatures();
         // add new objects
         $languages = Language::getLanguages(false);
         foreach ($_POST as $key => $val) {
             if (preg_match('/^feature_([0-9]+)_value/i', $key, $match)) {
                 if (!empty($val)) {
                     foreach ($val as $v) {
                         $product->addFeaturesToDB($match[1], $v);
                     }
                 } else {
                     if ($default_value = $this->checkFeatures($languages, $match[1])) {
                         $id_value = $product->addFeaturesToDB($match[1], 0, 1);
                         foreach ($languages as $language) {
                             if ($cust = Tools::getValue('custom_' . $match[1] . '_' . (int) $language['id_lang'])) {
                                 $product->addFeaturesCustomToDB($id_value, (int) $language['id_lang'], $cust);
                             } else {
                                 $product->addFeaturesCustomToDB($id_value, (int) $language['id_lang'], $default_value);
                             }
                         }
                     }
                 }
             }
         }
     } else {
         $this->errors[] = Tools::displayError('A product must be created before adding features.');
     }
 }
Exemplo n.º 29
0
 /**
  * @see ObjectModel::delete()
  */
 public function delete()
 {
     if (!$this->hasMultishopEntries() || Shop::getContext() == Shop::CONTEXT_ALL) {
         $result = Db::getInstance()->executeS('SELECT id_product_attribute FROM ' . _DB_PREFIX_ . 'product_attribute_combination WHERE id_attribute = ' . (int) $this->id);
         $products = array();
         foreach ($result as $row) {
             $combination = new Combination($row['id_product_attribute']);
             $newRequest = Db::getInstance()->executeS('SELECT id_product, default_on FROM ' . _DB_PREFIX_ . 'product_attribute WHERE id_product_attribute = ' . (int) $row['id_product_attribute']);
             foreach ($newRequest as $value) {
                 if ($value['default_on'] == 1) {
                     $products[] = $value['id_product'];
                 }
             }
             $combination->delete();
         }
         foreach ($products as $product) {
             $result = Db::getInstance()->executeS('SELECT id_product_attribute FROM ' . _DB_PREFIX_ . 'product_attribute WHERE id_product = ' . (int) $product . ' LIMIT 1');
             foreach ($result as $row) {
                 if (Validate::isLoadedObject($product = new Product((int) $product))) {
                     $product->deleteDefaultAttributes();
                     $product->setDefaultAttribute($row['id_product_attribute']);
                 }
             }
         }
         // Delete associated restrictions on cart rules
         CartRule::cleanProductRuleIntegrity('attributes', $this->id);
         /* Reinitializing position */
         $this->cleanPositions((int) $this->id_attribute_group);
     }
     $return = parent::delete();
     if ($return) {
         Hook::exec('actionAttributeDelete', array('id_attribute' => $this->id));
     }
     return $return;
 }
 public function postCreate()
 {
     $validator = Validator::make(Input::all(), Product::$rules);
     if ($validator->passes()) {
         $product = new Product();
         $product->title = Input::get('title');
         $product->description = Input::get('description');
         $id = Input::get('product_id');
         $skuAsset = sprintf("%06s", $id);
         $product->sku = 'INDE' . $skuAsset;
         $product->category_id = Input::get('category_id');
         $product->subcategory_id = Input::get('subcategory_id');
         $product->price = Input::get('price');
         $product->weight = Input::get('weight');
         $product->supplier_id = Auth::user()->id;
         $product->image = 'images/products/INDE' . $skuAsset;
         $product->save();
         $details = new Detail();
         $details->details = Input::get('details');
         $details->model = Input::get('model');
         $details->brand = Input::get('brand');
         $details->moredescription = Input::get('moredescription');
         $details->product_id = Input::get('product_id');
         $details->save();
         return Response::json('success', 200);
     } else {
         return $validator->errors;
     }
 }