Jump to content

PS 1.5: Carrier ID change (increment) after saving


Coluccini

Recommended Posts

Hi,

I've just noticed that after you save some changes on a Carrier at the backoffice, that Carrier ID change to the next auto increment ID. Is this suppose to happen or is this a bug? Can anyone help me on how can I avoid this from happening (I need the ID to be static so I can use it for a javascript reference).

I'm using PS version 1.5.4.0.

Thanks!

Link to comment
Share on other sites

mhmmm I'm checking at the MySQL db and it appears that the problem it isn't that the ID it changing but it looks like every time I modify a Carrier it is save as a new one, and the previous one is deleted. I guess there is a logic behind this but I can't figure it out.

 

Note: I have never changed anything at the BO. This is a default behavior

Link to comment
Share on other sites

  • 1 month later...

This is not a bug, this is feature, let's assume that someone already place an order with Carrier ID 20 (shipping costs $20), you changed that price and what now? PrestaShop save this old carrier, disable it and create new one with new price, it's seems ok for me.

 

That makes sense, but here is my situation.

 

While i made changes and settings to the store, before is launched, i managed to have carrier IDs like 25 and 27, even though i just have 2 carriers. Is there a way to have that reset? It just looks better when they show as 1 and 2, at least before launch :). I don't mind changing themself later..

Link to comment
Share on other sites

  • 2 weeks later...

Hello Coluccini I have the same problem and maybe a solution.

 

In my case, i need a unique ID for the carrier (logical carrier in our company, not carrier in prestashop), the id_carrier from table prefix_carrier don't work (because it changes), and the name don't work (sometimes it changes for cosmetics reasons)

 

So i will add a column carrier_code with strings like 'UPSXXX', 'CARRIER_Y' ... and override the duplication function to keep it  in the new carrier. In my case this codes are usefull to exchange data to another website but you can create your own ids (numeric for example)

 

I'm on the Prestashop 1.4 so i don't have code to give to you, hope that helps you

 

Donorsi you can change it in the database manually (remove all other lines from prefix_carrier and edit the last two of them to change id) only if you don't have changed things in the others tabs (like price range). In that case you have to change references in other tables it's a lot of work to juste have nice ids.

Edited by v1c3nt (see edit history)
Link to comment
Share on other sites

  • 8 months later...

Hello... I'm using prestashop with some modifications and had to made the same ID always. I don't need historic views, and there is no sense since you can't see it anywhere... 
Well, you can do a little trick, inverting the history logic. You'll keep the duplications logic and history, but will always use the same id. I do not recommend doing it because I don't know the consequences, so use it at your own risk.
 
Using PS1.6.0.14, file controllers/admin/AdminCarrierWizardController.php, line 770. You can try something like this is any version:
 

public function ajaxProcessFinishStep()
{
...
                if (Validate::isLoadedObject($new_carrier))
                {
                    // inverting some logic to keep the same id always
                    $aux = $new_carrier;
                    $new_carrier = $current_carrier;
                    $current_carrier = $aux;
                    // Set flag deteled to true for historization
                    $current_carrier->deleted = true;
                ...
}

 
The other and recommended way to keep track the way Prestashop does is using the hook "actionCarrierUpdate".

 

Best, Eder.

Link to comment
Share on other sites

  • 1 year later...
  • 1 month later...
  • 2 months later...

I did this to 1.6.1.10 and it seems to be working with no historic carrier id data collected.  controllers/admin/AdminCarrierWizardController.php starting at line 755 in the function ajaxProcessFinishStep

if ($id_carrier = Tools::getValue('id_carrier'))
{
	$carrier = new Carrier((int)$id_carrier);
	if (Validate::isLoadedObject($carrier))
	{
		// Fill the carrier object with form data
		$this->copyFromPost($carrier, $this->table);
		$carrier->update();
		$carrier->setTaxRulesGroup((int)Tools::getValue('id_tax_rules_group'));
		
	}
}

I also had to change the range code at line 665

if ($range_type == Carrier::SHIPPING_METHOD_WEIGHT)
{
	if (!RangeWeight::rangeExist((int)$carrier->id, (float)$delimiter1, (float)$range_sup[$key])){
		if(!RangeWeight::getRanges((int)$carrier->id)){
			$range = new RangeWeight();
		}
		else{
			$range= new RangeWeight((int)$key);
		}
	}
		
	else
	{
		$range = new RangeWeight((int)$key);
		$add_range = false;
	}
}

if ($range_type == Carrier::SHIPPING_METHOD_PRICE)
{
	if (!RangePrice::rangeExist((int)$carrier->id, (float)$delimiter1, (float)$range_sup[$key]))
	{
		if(!RangePrice::getRanges((int)$carrier->id)){
			$range = new RangePrice();
		}
		else{
			$range= new RangePrice((int)$key);
		}
	}
		
	else
	{
		$range = new RangePrice((int)$key);
		$add_range = false;
	}
}



			
				


	Edited  by treyj45
	
	
		(see edit history)
		
	

			
		
  • Thanks 1
Link to comment
Share on other sites

  • 1 year later...
On 3/13/2017 at 10:32 PM, treyj45 said:

I did this to 1.6.1.10 and it seems to be working with no historic carrier id data collected.  controllers/admin/AdminCarrierWizardController.php starting at line 755 in the function ajaxProcessFinishStep

I also had to change the range code at line 665

Thanks.
In our new project we want to keep the carrier id. If anything changes we believe it should behave like the product and other objects.
And you just saved me some time trying to solve the range issue.

Link to comment
Share on other sites

  • 1 year later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...