agarmur Posted June 20, 2022 Share Posted June 20, 2022 Hello, I am creating a webservice to be able to create products, I seek a means of putting a tax compared to a given number, in a product there is a function tax_rate, when I implement it and that thereafter I echo $product->getTaxesRate(); It returns: 0 Here is my complete code : $xml = simplexml_load_file('php://input'); $product = new Product($xml->id); $product->category = [2, 3]; $product->id_category_default = (int)$xml->id_category_default; $product->name = $xml->name; $product->price = $xml->price; //prix $product->unit_price = $xml->unit_price; //prix unitaire $product->wholesale_price = $xml->wholesale_price; //prix de gros $product->ecotax = $xml->ecotax; $product->ean13 = $xml->ean13; //code barre $product->tax_rate = 30; $product->description = html_entity_decode($xml->description); $product->description_short = html_entity_decode($xml->description_short); $product->reference = $xml->reference; $product->weight = $xml->weight; //poids $product->height = $xml->height; //hauteur $product->width = $xml->width; //largeur $product->depth = $xml->depth; //profondeur $product->minimal_quantity = (int)$xml->minimal_quantity; // quantité minimal $product->available_date = $xml->available_date; $product->delivery_in_stock = $xml->delivery_in_stock; $product->delivery_out_stock = $xml->delivery_out_stock; $product->additional_shipping_cost = $xml->shipping_cost; $product->id_manufacturer = 1; $product->manufacturer_name = $xml->manufacturer_name; $product->indexed = 1; $product->redirect_type = '301'; $product->active = true; if ($xml->online_only == "true") { $product->online_only = true; } else { $product->online_only = false; } if ($xml->available_for_order == "true") { $product->available_for_order = true; } else { $product->available_for_order = false; } if ($xml->show_price == "true") { $product->show_price = true; } else { $product->show_price = false; } $product->save(); $product->updateCategories($product->category); // STOCK $e = $product->getDefaultIdProductAttribute(); StockAvailable::setQuantity($product->id, $e, $xml->quantity); //IMAGE $nb = count($xml->urlImage) - 1; $i = 0; $a = 1; while ($i <= $nb) { $image = new Image(); $image->id_product = $product->id; $image->position = Image::getHighestPosition($product->id) + $a++; if ($i >= 1) { $image->cover = false; } else { $image->cover = true; } $image->image_format = 'jpg'; $image->save(); $this->copyImg((int)$product->id, (int)$image->id, ($xml->urlImage[$i++]), 'products', false); } echo $product->getTaxesRate(); Thanks ! Link to comment Share on other sites More sharing options...
lordignus Posted June 21, 2022 Share Posted June 21, 2022 Instead of setting $product->tax_rate, you need to set $product->id_tax_rules_group to whatever Tax Rule gives 30% tax. If that's the most commonly used Tax Rule for existing products in your shop, you can get the ID with Product::getIdTaxRulesGroupMostUsed(); So, instead of $product->tax_rate = 30; Try: $product->id_tax_rules_group = Product::getIdTaxRulesGroupMostUsed(); Link to comment Share on other sites More sharing options...
agarmur Posted June 21, 2022 Author Share Posted June 21, 2022 il y a 28 minutes, lordignus a dit : Instead of setting $product->tax_rate, you need to set $product->id_tax_rules_group to whatever Tax Rule gives 30% tax. If that's the most commonly used Tax Rule for existing products in your shop, you can get the ID with Product::getIdTaxRulesGroupMostUsed(); So, instead of $product->tax_rate = 30; Try: $product->id_tax_rules_group = Product::getIdTaxRulesGroupMostUsed(); thank you it works ! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now