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)

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 10:22 PM.

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