X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   General questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=66)
-   -   Default Product Values (https://forum.x-cart.com/showthread.php?t=72926)

superdave144 10-16-2015 09:21 AM

Default Product Values
 
How do you change the default product values? I would like the default product quantity to be 1.

razortw 10-16-2015 11:08 AM

Re: Default Product Values
 
Quote:

Originally Posted by superdave144
How do you change the default product values? I would like the default product quantity to be 1.

Hello.
Please specify your X-Cart version.
It would be useful to add it into your signature.
Thanks.

superdave144 10-16-2015 11:15 AM

Re: Default Product Values
 
5126 I think

BrianY 10-18-2015 05:30 PM

Re: Default Product Values
 
Dave,

Are you talking about the default quantity on the product page when a customer adds the item to the cart? If so, I believe the default is 1.

To change this number go to the Admin area of your X-Cart and navigate to the details page for an individual product. On this page select the "Inventory tracking" tab. Here you can change the Minimum purchase quantity.

superdave144 10-19-2015 01:52 AM

Re: Default Product Values
 
When you are adding a new product to the product catalog. The product has default values like quantity 1000

BrianY 10-19-2015 03:23 AM

Re: Default Product Values
 
Quote:

Originally Posted by superdave144
When you are adding a new product to the product catalog. The product has default values like quantity 1000


To change the default would require a custom module in XC5. When creating the new product you have a lot of the standard options on the "Add product" page in admin, including the "Quantity in stock" field. I guess you want to streamline the adding products and deal with as few of these fields as possible.

Another option after adding all of the products for a category is to look at the products as a list by clicking into the category. There you can change the "In stock" value for multiple products with one Save action.

Additionally, if importing products you can set this value to whatever you want in your import file. Even if adding the products by hand and wanting a quick way to bulk edit, you could export, edit the .csv, and re-import with the new values.

Hope some of this helps.

superdave144 10-19-2015 05:26 AM

Re: Default Product Values
 
Ok Thank you Brian. Maybe having a button on the bottom of the product page "Set as product defaults" might be a nice feature to add to x-cart.

razortw 10-19-2015 11:11 AM

Re: Default Product Values
 
Quote:

Originally Posted by superdave144
5126 I think

Thanks.
To change the default quantity you should change the value of the AMOUNT_DEFAULT_INV_TRACK constant in the /classes/XLite/Model/Inventory.php file (line 49)
By default it is
Code:

const AMOUNT_DEFAULT_INV_TRACK = 1000;
Just change it to
Code:

const AMOUNT_DEFAULT_INV_TRACK = 1;
and re-deploy the store.

BrianY 10-19-2015 11:27 AM

Re: Default Product Values
 
Quote:

Originally Posted by razortw
Thanks.
To change the default quantity you should change the value of the AMOUNT_DEFAULT_INV_TRACK constant in the /classes/XLite/Model/Inventory.php file (line 49)
By default it is
Code:

const AMOUNT_DEFAULT_INV_TRACK = 1000;
Just change it to
Code:

const AMOUNT_DEFAULT_INV_TRACK = 1;
and re-deploy the store.


Igor,

If he upgrades XC5 will these changes remain?

superdave144 10-19-2015 11:29 AM

Re: Default Product Values
 
Yes! Thank you! I'll try tonight and get back to you.

razortw 10-19-2015 11:38 AM

Re: Default Product Values
 
Quote:

Originally Posted by BrianY
Igor,

If he upgrades XC5 will these changes remain?

No, this will be overwritten during the upgrade.
As you said earlier, any change to X-Cart logic must be implemented as a module in order to avoid it getting rolled back after upgrade.

superdave144 10-19-2015 01:29 PM

Re: Default Product Values
 
That worked! Thank you!

razortw 10-21-2015 07:09 AM

Re: Default Product Values
 
Quote:

Originally Posted by superdave144
That worked! Thank you!

Great! I'm glad that I could help.

superdave144 11-30-2016 12:16 PM

Re: Default Product Values
 
This fix doesn't seem to be working anymore. Is there a new place to put this value?

qualiteam 12-05-2016 12:43 AM

Re: Default Product Values
 
As far as I see the constant is still there (in the most recent 5.3.2.x version).

However, I think a better way of changing the default stock level is decorating the \XLite\Model\Product::getDefaultAmount() method, not AMOUNT_DEFAULT_INV_TRACK constant itself.

Something like this:
PHP Code:

// File: classes/XLite/Module/DEV_ID/MODULE_ID/Model/Product.php

namespace XLite\Module\DEV_ID\MODULE_ID\Model;

class 
Product extends \XLite\Model\Product implements \XLite\Base\IDecorator
{
    
/**
     * Default qty value to show to customers
     *
     * @return integer
     */
    
public function getDefaultAmount()
    {
        return 
1;
    }



superdave144 12-05-2016 05:45 AM

Re: Default Product Values
 
Ok which file do I need to append this to? Am I adding code to a file or modifying existing code?

qualiteam 12-05-2016 10:21 AM

Re: Default Product Values
 
You should never edit existing files. Custom modification must be done as isolated modules with new files - this will help you to adapt the changes for future X-Cart versions.

The above is for a new PHP script - classes/XLite/Module/DEV_ID/MODULE_ID/Model/Product.php (you should replace DEV_ID and MODULE_ID with your ones). Of course, you should also add Main.php script as per the documentation.

superdave144 12-05-2016 12:30 PM

Re: Default Product Values
 
I'm sorry I've never done this before. Can you please provide a procedure?

qualiteam 12-05-2016 11:01 PM

Re: Default Product Values
 
Please follow this tutorial:
http://devs.x-cart.com/en/getting_started/step_1_-_creating_simplest_module.html

You are to create a new module and add the file that I posted the source code for above.

superdave144 12-06-2016 10:44 AM

Re: Default Product Values
 
Ok I added the new module and enabled it. The Main.php is configured in /classes/XLite/Module/JRG/Quantity directory. I created the new product.php file in the /classes/XLite/Module/JRG/Quantity/Model/ directory. I redeployed the store after the module was created as well. The default quantity is still showing 1000. Do I need a reference from the Main.php to the product.php file?

qualiteam 12-11-2016 10:18 PM

Re: Default Product Values
 
Quote:

Originally Posted by superdave144
Ok I added the new module and enabled it. The Main.php is configured in /classes/XLite/Module/JRG/Quantity directory. I created the new product.php file in the /classes/XLite/Module/JRG/Quantity/Model/ directory. I redeployed the store after the module was created as well. The default quantity is still showing 1000. Do I need a reference from the Main.php to the product.php file?


You don't need a reference.
But did you enable your custom module on the Modules page in the back end?
Also, did you replace "DEV_ID" with "JRG", and "MODULE_ID" with "Quantity" in the module's source code?
You may also check if there is product.php file in the var/run/classes/XLite/Module/JRG/Quantity/Model/ directory and whether it is not empty.

superdave144 12-12-2016 06:31 AM

Re: Default Product Values
 
Here is the product.php file located in /opt/bitnami/apps/xcart/htdocs/classes/XLite/Module/JRG/Quantity/Model

// File: classes/XLite/Module/JRG/Quantity/Model/Product.php

namespace XLite\Module\JRG\Quantity\Model;

class Product extends \XLite\Model\Product implements \XLite\Base\IDecorator
{
/**
* Default qty value to show to customers
*
* @return integer
*/
public function getDefaultAmount()
{
return 1;
}
}


Here is the main.php file located in /opt/bitnami/apps/xcart/htdocs/classes/XLite/Module/JRG/Quantity

<?php
namespace XLite\Module\JRG\Quantity;

abstract class Main extends \XLite\Module\AModule
{
/**
* Just Retro Games
*
* @return string
*/
public static function getAuthorName()
{
return 'Just Retro Games';
}

/**
* Module name
*
* @return string
*/
public static function getModuleName()
{
return 'Default Item Quantity';
}

/**
* Get module major version
*
* @return string
*/
public static function getMajorVersion()
{
return '5.3';
}

/**
* Module version
*
* @return string
*/
public static function getMinorVersion()
{
return 0;
}

/**
* Module description
*
* @return string
*/
public static function getDescription()
{
return 'Sets the default item quantity to 1 instead of 1000';
}

There is no model subfolder in this directory. /opt/bitnami/apps/xcart/htdocs/var/run/classes/XLite/Module/JRG/Quantity

qualiteam 12-19-2016 04:50 AM

Re: Default Product Values
 
1 Attachment(s)
Quote:

Originally Posted by superdave144
There is no model subfolder in this directory. /opt/bitnami/apps/xcart/htdocs/var/run/classes/XLite/Module/JRG/Quantity


It sounds as you missed the "<?php" in the first line in that file, so XC5 doesn't consider this as a PHP script and ignores it.

Anyway, I've tried the code on my local installation and I see that overriding the method is not enough. You should also change \XLite\Model\Product::__constructor($data) as the $amount property is initialised with the constant, not with the value returned by the method. So, you should override it in the constructor as well.

Please check the attached custom module - it should work for you.

superdave144 12-20-2016 05:31 AM

Re: Default Product Values
 
That worked! Thank you very much Alex!


All times are GMT -8. The time now is 01:39 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.