コード例 #1
0
 /**
  * Delete a product attribute
  *
  * @param int $idAttribute The attribute ID
  * @param int $idProduct The product ID
  *
  * @return array
  */
 public function ajaxProcessDeleteProductAttribute($idAttribute, $idProduct)
 {
     if (!\CombinationCore::isFeatureActive()) {
         return false;
     }
     if ($idProduct && \ValidateCore::isUnsignedId($idProduct) && \ValidateCore::isLoadedObject($product = new \ProductCore($idProduct))) {
         if (($depends_on_stock = \StockAvailableCore::dependsOnStock($idProduct)) && \StockAvailableCore::getQuantityAvailableByProduct($idProduct, $idAttribute)) {
             return array('status' => 'error', 'message' => 'It is not possible to delete a combination while it still has some quantities in the Advanced Stock Management. You must delete its stock first.');
         } else {
             $product->deleteAttributeCombination((int) $idAttribute);
             $product->checkDefaultAttributes();
             \ToolsCore::clearColorListCache((int) $product->id);
             if (!$product->hasAttributes()) {
                 $product->cache_default_attribute = 0;
                 $product->update();
             } else {
                 \ProductCore::updateDefaultAttribute($idProduct);
             }
             if ($depends_on_stock && !\StockCore::deleteStockByIds($idProduct, $idAttribute)) {
                 return array('status' => 'error', 'message' => 'Error while deleting the stock');
             } else {
                 return array('status' => 'ok', 'message' => 'Successful deletion');
             }
         }
     } else {
         return array('status' => 'error', 'message' => 'You cannot delete this attribute.');
     }
 }
コード例 #2
0
 /**
  * processProductAttribute
  * Update a combination
  *
  * @param object $product
  * @param array $combinationValues the posted values
  *
  * @return \AdminProductsControllerCore instance
  */
 public function processProductAttribute($product, $combinationValues)
 {
     $id_product_attribute = (int) $combinationValues['id_product_attribute'];
     $images = [];
     if (!\CombinationCore::isFeatureActive() || $id_product_attribute == 0) {
         return;
     }
     if (!isset($combinationValues['attribute_wholesale_price'])) {
         $combinationValues['attribute_wholesale_price'] = 0;
     }
     if (!isset($combinationValues['attribute_price_impact'])) {
         $combinationValues['attribute_price_impact'] = 0;
     }
     if (!isset($combinationValues['attribute_weight_impact'])) {
         $combinationValues['attribute_weight_impact'] = 0;
     }
     if (!isset($combinationValues['attribute_ecotax'])) {
         $combinationValues['attribute_ecotax'] = 0;
     }
     if (isset($combinationValues['attribute_default']) && $combinationValues['attribute_default'] == 1) {
         $product->deleteDefaultAttributes();
     }
     if (!empty($combinationValues['id_image_attr'])) {
         $images = $combinationValues['id_image_attr'];
     }
     $product->updateAttribute($id_product_attribute, $combinationValues['attribute_wholesale_price'], $combinationValues['attribute_price'] * $combinationValues['attribute_price_impact'], $combinationValues['attribute_weight'] * $combinationValues['attribute_weight_impact'], $combinationValues['attribute_unity'] * $combinationValues['attribute_unit_impact'], $combinationValues['attribute_ecotax'], $images, $combinationValues['attribute_reference'], $combinationValues['attribute_ean13'], isset($combinationValues['attribute_default']) && $combinationValues['attribute_default'] == 1, isset($combinationValues['attribute_location']) ? $combinationValues['attribute_location'] : null, $combinationValues['attribute_upc'], $combinationValues['attribute_minimal_quantity'], $combinationValues['available_date_attribute'], false, array(), $combinationValues['attribute_isbn']);
     \StockAvailableCore::setProductDependsOnStock((int) $product->id, $product->depends_on_stock, null, $id_product_attribute);
     \StockAvailableCore::setProductOutOfStock((int) $product->id, $product->out_of_stock, null, $id_product_attribute);
     $product->checkDefaultAttributes();
     if (isset($combinationValues['attribute_default']) && $combinationValues['attribute_default'] == 1) {
         \ProductCore::updateDefaultAttribute((int) $product->id);
         if (isset($id_product_attribute)) {
             $product->cache_default_attribute = (int) $id_product_attribute;
         }
         if ($available_date = $combinationValues['available_date_attribute']) {
             $product->setAvailableDate($available_date);
         } else {
             $product->setAvailableDate();
         }
     }
     $this->processQuantityUpdate($product, $combinationValues['attribute_quantity'], $id_product_attribute);
 }
コード例 #3
0
    /**
     * Get all attributes ids for a given group
     *
     * @param int $id_group Attribute group id
     * @param bool $not_null Get only not null fields if true
     * @return array Attributes
     */
    public static function getAttributeIdsByGroup($id_group, $not_null = false)
    {
        if (!\CombinationCore::isFeatureActive()) {
            return array();
        }
        $result = \DbCore::getInstance()->executeS('
			SELECT DISTINCT a.`id_attribute`
			FROM `' . _DB_PREFIX_ . 'attribute_group` ag
			LEFT JOIN `' . _DB_PREFIX_ . 'attribute` a
				ON a.`id_attribute_group` = ag.`id_attribute_group`
			' . \ShopCore::addSqlAssociation('attribute_group', 'ag') . '
			' . \ShopCore::addSqlAssociation('attribute', 'a') . '
			WHERE ag.`id_attribute_group` = ' . (int) $id_group . '
			' . ($not_null ? 'AND a.`id_attribute` IS NOT NULL' : '') . '
			ORDER BY a.`position` ASC
		');
        return array_map(function ($a) {
            return $a['id_attribute'];
        }, $result);
    }
コード例 #4
0
ファイル: Configuration.php プロジェクト: M03G/PrestaShop
 /**
  * Return if Combination feature is active or not
  * @return bool
  */
 public function combinationIsActive()
 {
     return \CombinationCore::isFeatureActive();
 }