/** * 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.'); } }
/** * prepare attribute groups * * @return array */ protected function prepareAttributeGroups() { $result = array(); if ($this->currentProduct->hasAttributes()) { //function getAttributesInformationsByProduct available from version 1.5.0.1 if (version_compare(_PS_VERSION_, '1.5.0.1', '<')) { $attributes = BWProduct::getAttributesInformationsByProduct($this->currentProduct->id, $this->getPlugin()->getLanguageId()); } else { $attributes = Product::getAttributesInformationsByProduct($this->currentProduct->id); } $addedGroup = array(); foreach ($attributes as $attribute) { if (!in_array($attribute['id_attribute_group'], $addedGroup)) { $attributeItem = new Shopgate_Model_Catalog_AttributeGroup(); $attributeItem->setUid($attribute['id_attribute_group']); $attributeItem->setLabel($attribute['group']); $result[] = $attributeItem; $addedGroup[] = $attribute['id_attribute_group']; } } } return $result; }