コード例 #1
0
 function add()
 {
     if (!empty($this->data)) {
         $this->Browser->create();
         if ($this->Browser->save($this->data)) {
             App::import('Model', 'Operatingsystem');
             App::import('Model', 'Combination');
             $os = new Operatingsystem();
             $combination = new Combination();
             $os->recursive = 0;
             $all_os = $os->find('all');
             foreach ($all_os as $value) {
                 $data = array();
                 $data['Combination']['operatingsystem_id'] = $value['Operatingsystem']['id'];
                 $data['Combination']['browser_id'] = $this->Browser->id;
                 $combination->create();
                 $combination->save($data);
             }
             $this->Session->setFlash(__('The Browser has been saved', true));
             $this->redirect(array('action' => 'index'));
         } else {
             $this->Session->setFlash(__('The Browser could not be saved. Please, try again.', true));
         }
     }
 }
コード例 #2
0
 public function testCombinationSuccess()
 {
     $combination = new Combination();
     $combination->isPublic = true;
     $combination->protocol_id = 1;
     $combination->power_generator_id = 1;
     $combination->needle_id = 1;
     $this->assertTrue($combination->save());
 }
コード例 #3
0
 function add()
 {
     if (!empty($this->data)) {
         $this->Operatingsystem->create();
         if ($this->Operatingsystem->save($this->data)) {
             $browser = new Browser();
             $combination = new Combination();
             $browser->recursive = 0;
             $all_browser = $browser->find('all');
             foreach ($all_browser as $value) {
                 $data = array();
                 $data['Combination']['browser_id'] = $value['Browser']['id'];
                 $data['Combination']['operatingsystem_id'] = $this->Operatingsystem->id;
                 $combination->create();
                 $combination->save($data);
             }
             $this->Session->setFlash(__('The Operatingsystem has been saved', true));
             $this->redirect(array('action' => 'index'));
         } else {
             $this->Session->setFlash(__('The Operatingsystem could not be saved. Please, try again.', true));
         }
     }
 }
コード例 #4
0
 public function processUpdate()
 {
     $existing_product = $this->object;
     $this->checkProduct();
     if (!empty($this->errors)) {
         $this->display = 'edit';
         return false;
     }
     $id = (int) Tools::getValue('id_' . $this->table);
     /* Update an existing product */
     if (isset($id) && !empty($id)) {
         $object = new $this->className((int) $id);
         $this->object = $object;
         if (Validate::isLoadedObject($object)) {
             $this->_removeTaxFromEcotax();
             $product_type_before = $object->getType();
             $this->copyFromPost($object, $this->table);
             $object->indexed = 0;
             if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP) {
                 $object->setFieldsToUpdate((array) Tools::getValue('multishop_check'));
             }
             // Duplicate combinations if not associated to shop
             if ($this->context->shop->getContext() == Shop::CONTEXT_SHOP && !$object->isAssociatedToShop()) {
                 $is_associated_to_shop = false;
                 $combinations = Product::getProductAttributesIds($object->id);
                 if ($combinations) {
                     foreach ($combinations as $id_combination) {
                         $combination = new Combination((int) $id_combination['id_product_attribute']);
                         $default_combination = new Combination((int) $id_combination['id_product_attribute'], null, (int) $this->object->id_shop_default);
                         $def = ObjectModel::getDefinition($default_combination);
                         foreach ($def['fields'] as $field_name => $row) {
                             $combination->{$field_name} = ObjectModel::formatValue($default_combination->{$field_name}, $def['fields'][$field_name]['type']);
                         }
                         $combination->save();
                     }
                 }
             } else {
                 $is_associated_to_shop = true;
             }
             if ($object->update()) {
                 // If the product doesn't exist in the current shop but exists in another shop
                 if (Shop::getContext() == Shop::CONTEXT_SHOP && !$existing_product->isAssociatedToShop($this->context->shop->id)) {
                     $out_of_stock = StockAvailable::outOfStock($existing_product->id, $existing_product->id_shop_default);
                     $depends_on_stock = StockAvailable::dependsOnStock($existing_product->id, $existing_product->id_shop_default);
                     StockAvailable::setProductOutOfStock((int) $this->object->id, $out_of_stock, $this->context->shop->id);
                     StockAvailable::setProductDependsOnStock((int) $this->object->id, $depends_on_stock, $this->context->shop->id);
                 }
                 PrestaShopLogger::addLog(sprintf($this->l('%s edition', 'AdminTab', false, false), $this->className), 1, null, $this->className, (int) $this->object->id, true, (int) $this->context->employee->id);
                 if (in_array($this->context->shop->getContext(), array(Shop::CONTEXT_SHOP, Shop::CONTEXT_ALL))) {
                     if ($this->isTabSubmitted('Shipping')) {
                         $this->addCarriers();
                     }
                     if ($this->isTabSubmitted('Associations')) {
                         $this->updateAccessories($object);
                     }
                     if ($this->isTabSubmitted('Suppliers')) {
                         $this->processSuppliers();
                     }
                     if ($this->isTabSubmitted('Features')) {
                         $this->processFeatures();
                     }
                     if ($this->isTabSubmitted('Combinations')) {
                         $this->processProductAttribute();
                     }
                     if ($this->isTabSubmitted('Prices')) {
                         $this->processPriceAddition();
                         $this->processSpecificPricePriorities();
                     }
                     if ($this->isTabSubmitted('Customization')) {
                         $this->processCustomizationConfiguration();
                     }
                     if ($this->isTabSubmitted('Attachments')) {
                         $this->processAttachments();
                     }
                     $this->updatePackItems($object);
                     // Disallow avanced stock management if the product become a pack
                     if ($product_type_before == Product::PTYPE_SIMPLE && $object->getType() == Product::PTYPE_PACK) {
                         StockAvailable::setProductDependsOnStock((int) $object->id, false);
                     }
                     $this->updateDownloadProduct($object, 1);
                     $this->updateTags(Language::getLanguages(false), $object);
                     if ($this->isProductFieldUpdated('category_box') && !$object->updateCategories(Tools::getValue('categoryBox'))) {
                         $this->errors[] = Tools::displayError('An error occurred while linking the object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('To categories');
                     }
                 }
                 if ($this->isTabSubmitted('Warehouses')) {
                     $this->processWarehouses();
                 }
                 if (empty($this->errors)) {
                     if (in_array($object->visibility, array('both', 'search')) && Configuration::get('PS_SEARCH_INDEXATION')) {
                         Search::indexation(false, $object->id);
                     }
                     // Save and preview
                     if (Tools::isSubmit('submitAddProductAndPreview')) {
                         $this->redirect_after = $this->getPreviewUrl($object);
                     } else {
                         // Save and stay on same form
                         if ($this->display == 'edit') {
                             $this->confirmations[] = $this->l('Update successful');
                             $this->redirect_after = self::$currentIndex . '&id_product=' . (int) $this->object->id . (Tools::getIsset('id_category') ? '&id_category=' . (int) Tools::getValue('id_category') : '') . '&updateproduct&conf=4&key_tab=' . Tools::safeOutput(Tools::getValue('key_tab')) . '&token=' . $this->token;
                         } else {
                             // Default behavior (save and back)
                             $this->redirect_after = self::$currentIndex . (Tools::getIsset('id_category') ? '&id_category=' . (int) Tools::getValue('id_category') : '') . '&conf=4&token=' . $this->token;
                         }
                     }
                 } else {
                     $this->display = 'edit';
                 }
             } else {
                 if (!$is_associated_to_shop && $combinations) {
                     foreach ($combinations as $id_combination) {
                         $combination = new Combination((int) $id_combination['id_product_attribute']);
                         $combination->delete();
                     }
                 }
                 $this->errors[] = Tools::displayError('An error occurred while updating an object.') . ' <b>' . $this->table . '</b> (' . Db::getInstance()->getMsgError() . ')';
             }
         } else {
             $this->errors[] = Tools::displayError('An error occurred while updating an object.') . ' <b>' . $this->table . '</b> (' . Tools::displayError('The object cannot be loaded. ') . ')';
         }
         return $object;
     }
 }
コード例 #5
0
ファイル: Product.php プロジェクト: jicheng17/vipinsg
 /**
  * Update a product attribute
  *
  * @param integer $id_product_attribute Product attribute id
  * @param float $wholesale_price Wholesale price
  * @param float $price Additional price
  * @param float $weight Additional weight
  * @param float $unit
  * @param float $ecotax Additional ecotax
  * @param integer $id_image Image id
  * @param string $reference Reference
  * @param string $ean13 Ean-13 barcode
  * @param int $default Default On
  * @param string $upc Upc barcode
  * @param string $minimal_quantity Minimal quantity
  * @return array Update result
  */
 public function updateAttribute($id_product_attribute, $wholesale_price, $price, $weight, $unit, $ecotax, $id_images, $reference, $ean13, $default, $location = null, $upc = null, $minimal_quantity = null, $available_date = null, $update_all_fields = true, array $id_shop_list = array())
 {
     $combination = new Combination($id_product_attribute);
     if (!$update_all_fields) {
         $combination->setFieldsToUpdate(array('price' => !is_null($price), 'wholesale_price' => !is_null($wholesale_price), 'ecotax' => !is_null($ecotax), 'weight' => !is_null($weight), 'unit_price_impact' => !is_null($unit), 'default_on' => !is_null($ecotax), 'minimal_quantity' => !is_null($minimal_quantity), 'available_date' => !is_null($available_date)));
     }
     $price = str_replace(',', '.', $price);
     $weight = str_replace(',', '.', $weight);
     $combination->price = (double) $price;
     $combination->wholesale_price = (double) $wholesale_price;
     $combination->ecotax = (double) $ecotax;
     $combination->weight = (double) $weight;
     $combination->unit_price_impact = (double) $unit;
     $combination->reference = pSQL($reference);
     $combination->location = pSQL($location);
     $combination->ean13 = pSQL($ean13);
     $combination->upc = pSQL($upc);
     $combination->default_on = (int) $default;
     $combination->minimal_quantity = (int) $minimal_quantity;
     $combination->available_date = $available_date ? pSQL($available_date) : '0000-00-00';
     if (count($id_shop_list)) {
         $combination->id_shop_list = $id_shop_list;
     }
     $combination->save();
     if (!empty($id_images)) {
         $combination->setImages($id_images);
     }
     Product::updateDefaultAttribute($this->id);
     Hook::exec('actionProductAttributeUpdate', array('id_product_attribute' => $id_product_attribute));
     return true;
 }
コード例 #6
0
ファイル: Product.php プロジェクト: yewed/share
    /**
     * Duplicate attributes when duplicating a product
     *
     * @param int $id_product_old Old product id
     * @param int $id_product_new New product id
     */
    public static function duplicateAttributes($id_product_old, $id_product_new)
    {
        $return = true;
        $combination_images = array();
        $result = Db::getInstance()->executeS('
		SELECT pa.*, product_attribute_shop.*
			FROM `' . _DB_PREFIX_ . 'product_attribute` pa
			' . Shop::addSqlAssociation('product_attribute', 'pa') . '
			WHERE pa.`id_product` = ' . (int) $id_product_old);
        $combinations = array();
        foreach ($result as $row) {
            $id_product_attribute_old = (int) $row['id_product_attribute'];
            if (!isset($combinations[$id_product_attribute_old])) {
                $id_combination = null;
                $id_shop = null;
                $result2 = Db::getInstance()->executeS('
				SELECT *
				FROM `' . _DB_PREFIX_ . 'product_attribute_combination`
					WHERE `id_product_attribute` = ' . $id_product_attribute_old);
            } else {
                $id_combination = (int) $combinations[$id_product_attribute_old];
                $id_shop = (int) $row['id_shop'];
                $context_old = Shop::getContext();
                $context_shop_id_old = Shop::getContextShopID();
                Shop::setContext(Shop::CONTEXT_SHOP, $id_shop);
            }
            $row['id_product'] = $id_product_new;
            unset($row['id_product_attribute']);
            $combination = new Combination($id_combination, null, $id_shop);
            foreach ($row as $k => $v) {
                $combination->{$k} = $v;
            }
            $return &= $combination->save();
            $id_product_attribute_new = (int) $combination->id;
            if ($result_images = Product::_getAttributeImageAssociations($id_product_attribute_old)) {
                $combination_images['old'][$id_product_attribute_old] = $result_images;
                $combination_images['new'][$id_product_attribute_new] = $result_images;
            }
            if (!isset($combinations[$id_product_attribute_old])) {
                $combinations[$id_product_attribute_old] = (int) $id_product_attribute_new;
                foreach ($result2 as $row2) {
                    $row2['id_product_attribute'] = $id_product_attribute_new;
                    $return &= Db::getInstance()->insert('product_attribute_combination', $row2);
                }
            } else {
                Shop::setContext($context_old, $context_shop_id_old);
            }
            //Copy suppliers
            $result3 = Db::getInstance()->executeS('
			SELECT *
			FROM `' . _DB_PREFIX_ . 'product_supplier`
			WHERE `id_product_attribute` = ' . (int) $id_product_attribute_old . '
			AND `id_product` = ' . (int) $id_product_old);
            foreach ($result3 as $row3) {
                unset($row3['id_product_supplier']);
                $row3['id_product'] = $id_product_new;
                $row3['id_product_attribute'] = $id_product_attribute_new;
                $return &= Db::getInstance()->insert('product_supplier', $row3);
            }
        }
        $impacts = self::getAttributesImpacts($id_product_old);
        if (is_array($impacts) && count($impacts)) {
            $impact_sql = 'INSERT INTO `' . _DB_PREFIX_ . 'attribute_impact` (`id_product`, `id_attribute`, `weight`, `price`) VALUES ';
            foreach ($impacts as $id_attribute => $impact) {
                $impact_sql .= '(' . (int) $id_product_new . ', ' . (int) $id_attribute . ', ' . (double) $impacts[$id_attribute]['weight'] . ', ' . (double) $impacts[$id_attribute]['price'] . '),';
            }
            $impact_sql = substr_replace($impact_sql, '', -1);
            $impact_sql .= ' ON DUPLICATE KEY UPDATE `price` = VALUES(price), `weight` = VALUES(weight)';
            Db::getInstance()->execute($impact_sql);
        }
        return !$return ? false : $combination_images;
    }
コード例 #7
0
ファイル: Product.php プロジェクト: rongandat/vatfairfoot
    /**
     * Duplicate attributes when duplicating a product
     *
     * @param integer $id_product_old Old product id
     * @param integer $id_product_new New product id
     */
    public static function duplicateAttributes($id_product_old, $id_product_new)
    {
        $return = true;
        $combination_images = array();
        $result = Db::getInstance()->executeS('
		SELECT pa.*, product_attribute_shop.*
			FROM `' . _DB_PREFIX_ . 'product_attribute` pa
			' . Shop::addSqlAssociation('product_attribute', 'pa') . '
			WHERE pa.`id_product` = ' . (int) $id_product_old);
        $combinations = array();
        foreach ($result as $row) {
            $id_product_attribute_old = (int) $row['id_product_attribute'];
            if (!isset($combinations[$id_product_attribute_old])) {
                $id_combination = null;
                $id_shop = null;
                $result2 = Db::getInstance()->executeS('
				SELECT *
				FROM `' . _DB_PREFIX_ . 'product_attribute_combination`
					WHERE `id_product_attribute` = ' . $id_product_attribute_old);
            } else {
                $id_combination = (int) $combinations[$id_product_attribute_old];
                $id_shop = (int) $row['id_shop'];
                $context_old = Shop::getContext();
                $context_shop_id_old = Shop::getContextShopID();
                Shop::setContext(Shop::CONTEXT_SHOP, $id_shop);
            }
            $row['id_product'] = $id_product_new;
            unset($row['id_product_attribute']);
            $combination = new Combination($id_combination, null, $id_shop);
            foreach ($row as $k => $v) {
                $combination->{$k} = $v;
            }
            $return &= $combination->save();
            $id_product_attribute_new = (int) $combination->id;
            if ($result_images = Product::_getAttributeImageAssociations($id_product_attribute_old)) {
                $combination_images['old'][$id_product_attribute_old] = $result_images;
                $combination_images['new'][$id_product_attribute_new] = $result_images;
            }
            if (!isset($combinations[$id_product_attribute_old])) {
                $combinations[$id_product_attribute_old] = (int) $id_product_attribute_new;
                foreach ($result2 as $row2) {
                    $row2['id_product_attribute'] = $id_product_attribute_new;
                    $return &= Db::getInstance()->insert('product_attribute_combination', $row2);
                }
            } else {
                Shop::setContext($context_old, $context_shop_id_old);
            }
        }
        return !$return ? false : $combination_images;
    }
コード例 #8
0
ファイル: ajax.php プロジェクト: prestamodule/erpillicopresta
         if ((int) $nbProducts['nb_products'] > 0) {
             $product_supplier = new ErpProductSupplier($nbProducts['id_product_supplier']);
             $product_supplier->product_supplier_price_te = $wholesale_price;
             $product_supplier->save();
         }
         /* If not global update of the product in any case */
         /*  Product */
         if ($id_product_attribute == '0') {
             $product = new Product($id_product);
             $product->wholesale_price = $wholesale_price;
             $product->save();
         } else {
             $combination = new Combination($id_product_attribute);
             $combination->id_product = $id_product;
             $combination->wholesale_price = $wholesale_price;
             $combination->save();
         }
         $update = DB::getInstance(_PS_USE_SQL_SLAVE_)->execute($query);
         echo $update;
     }
     break;
     /*  update delivery or cancel delivery  */
 /*  update delivery or cancel delivery  */
 case 'receipt_update':
 case 'receipt_cancel':
     $is_canceled = Tools::getValue('action') == 'receipt_update' ? 0 : 1;
     /*  update table ps_supply_order_receipt_history */
     $supply_order_receipt_history = new SupplyOrderReceiptHistory();
     $supply_order_receipt_history->id_supply_order_receipt_history = (int) Tools::getValue('id_supply_order_receipt_history');
     $supply_order_receipt_history->id = (int) Tools::getValue('id_supply_order_receipt_history');
     $supply_order_receipt_history->id_supply_order_detail = Tools::getValue('id_supply_order_detail');
コード例 #9
0
ファイル: item.docs.php プロジェクト: laiello/php-garden
$mat_1->belongs_to($company);
$mat_1->name = 'Skóra';
$mat_1->save();
$mat_2 = new Material();
$mat_2->belongs_to($company);
$mat_2->name = 'Drewno brzozowe';
$mat_2->save();
/** 1.6. Check if materials successfully created */
debug($mat_1->load());
debug($mat_2->load());
/** 1.7. Create a new material combination */
$comb = new Combination();
$comb->belongs_to($product);
$comb->has_multiple($mat_1, $mat_2);
$comb->price = '12.34';
$comb->save();
/** 1.8. Check if combination successfully created */
debug($comb->load());
/*
CREATE TABLE `product` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `company_id` int(10) unsigned NOT NULL,
  `name` text collate utf8_polish_ci NOT NULL,
  `elem_1` text collate utf8_polish_ci NOT NULL,
  `elem_2` text collate utf8_polish_ci NOT NULL,
  `elem_3` text collate utf8_polish_ci NOT NULL,
  `elem_4` text collate utf8_polish_ci NOT NULL,
  PRIMARY KEY  (`id`)
);
CREATE TABLE `combination` (
  `id` int(10) unsigned NOT NULL auto_increment,