Extend Stock (Solved)

Questions around the TYPO3 integration and plugins
Forum rules
Always add your TYPO3, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
mohal_04
Advanced
Posts: 108
Joined: 27 Mar 2018, 05:59

Re: Extend Stock (Solved)

Post by mohal_04 » 13 Apr 2018, 04:56

tenkraD wrote:
aimeos wrote:You should (!) only add the configuration and code you overwrite and remove the things that are the same as in the core. Especially in the configuration file (SQL statements that are the same as in the core file) and in the admin client (which should contain only the overwritten method and nothing else).

The setting for configuring your new admin client class is in general

Code: Select all

admin/jqadm/product/stock/name = Mystandard
and documentation can be found here:
https://aimeos.org/docs/Configuration/C ... stock/name
Accepted i updated the post above.
Just adding code i overwrite is not working for the file
/typo3conf/ext/mhaimeos/Resources/Private/Extensions/mhaimeos/admin/jqadm/src/Admin/JQAdm/Product/Stock/Mystandard.php. Why?

Thanks admin
Hi,

It should work. I overwrite client admin file and it worked.

./ext/myextension/admin/jqadm/src/Admin/JQAdm/Product/Price/Mystandard.php

Code: Select all

namespace Aimeos\Admin\JQAdm\Product\Price;

sprintf( 'price' ); // for translation


/**
 * Default implementation of product price JQAdm client.
 *
 * @package Admin
 * @subpackage JQAdm
 */
class Mystandard extends Standard
{
	/**
	 * Creates new and updates existing items using the data array
	 *
	 * @param \Aimeos\MShop\Product\Item\Iface $item Product item object without referenced domain items
	 * @param string[] $data Data array
	 */
	protected function fromArray( \Aimeos\MShop\Product\Item\Iface $item, array $data )
	{
		$context = $this->getContext();

		$manager = \Aimeos\MShop\Factory::createManager( $context, 'product' );
		$priceManager = \Aimeos\MShop\Factory::createManager( $context, 'price' );
		$listManager = \Aimeos\MShop\Factory::createManager( $context, 'product/lists' );
		$listTypeManager = \Aimeos\MShop\Factory::createManager( $context, 'product/lists/type' );

		$listIds = (array) $this->getValue( $data, 'product.lists.id', [] );
		$listItems = $manager->getItem( $item->getId(), array( 'price' ) )->getListItems( 'price', null, null, false );


		$listItem = $listManager->createItem();
		$listItem->setParentId( $item->getId() );
		$listItem->setDomain( 'price' );
		$listItem->setStatus( 1 );

		$newItem = $priceManager->createItem();
		$newItem->setDomain( 'product' );

		foreach( $listIds as $idx => $listid )
		{
			if( !isset( $listItems[$listid] ) )
			{
				$priceItem = clone $newItem;
				$litem = clone $listItem;
			}
			else
			{
				$litem = $listItems[$listid];
				$priceItem = $litem->getRefItem();
			}

			$priceItem->setStatus( $this->getValue( $data, 'price.status/' . $idx ) );
			$priceItem->setTypeId( $this->getValue( $data, 'price.typeid/' . $idx ) );
			$priceItem->setCurrencyId( $this->getValue( $data, 'price.currencyid/' . $idx ) );
			$priceItem->setQuantity( $this->getValue( $data, 'price.quantity/' . $idx, 1 ) );
			$priceItem->setValue( $this->getValue( $data, 'price.value/' . $idx, '0.00' ) );
			$priceItem->setMinimumadvertisedprice( $this->getValue( $data, 'price.minimumadvertisedprice/' . $idx, '0.00' ) );
			$priceItem->setProductioncost( $this->getValue( $data, 'price.productioncost/' . $idx, '0.00' ) );
			$priceItem->setIsShippingRestrictions($this->getValue($data, 'price.isshippingrestrictions/' . $idx, '0.00'));
			$priceItem->setCosts( $this->getValue( $data, 'price.costs/' . $idx, '0.00' ) );
			$priceItem->setRebate( $this->getValue( $data, 'price.rebate/' . $idx, '0.00' ) );
			$priceItem->setTaxRate( $this->getValue( $data, 'price.taxrate/' . $idx, '0.00' ) );

			$label = $priceItem->getQuantity() . ' ~ ' . $priceItem->getValue() . ' ' . $priceItem->getCurrencyId();
			$priceItem->setLabel( $item->getLabel() . ' :: ' . $label );

			$priceItem = $priceManager->saveItem( $priceItem );


			$conf = [];

			foreach( (array) $this->getValue( $data, 'config/' . $idx . '/key' ) as $num => $key )
			{
				$val = $this->getValue( $data, 'config/' . $idx . '/val/' . $num );

				if( trim( $key ) !== '' && $val !== null ) {
					$conf[$key] = trim( $val );
				}
			}

			$litem->setConfig( $conf );
			$litem->setPosition( $idx );
			$litem->setRefId( $priceItem->getId() );
			$litem->setTypeId( $this->getValue( $data, 'product.lists.typeid/' . $idx ) );
			$litem->setDateStart( $this->getValue( $data, 'product.lists.datestart/' . $idx ) );
			$litem->setDateEnd( $this->getValue( $data, 'product.lists.dateend/' . $idx ) );

			$listManager->saveItem( $litem, false );
		}


		$rmIds = [];
		$rmListIds = array_diff( array_keys( $listItems ), $listIds );

		foreach( $rmListIds as $id ) {
			$rmIds[] = $listItems[$id]->getRefId();
		}

		$listManager->deleteItems( $rmListIds  );
		$priceManager->deleteItems( $rmIds  );
	}
}
In this class I only overwrite fromArray() method and it is working fine. I extend Mystandard class with Standard class only. Both of these classes are in same directory. I am doing this all in... Aimeos: 2018.04 & Laravel: 5.6.

I wasted 4 years of my life doing OOP-less PHP. That's why I am facing too many problems now. Anyhow, I hope this helps you.

Thanks!

tenkraD
Advanced
Posts: 110
Joined: 25 Jul 2017, 08:38

Re: Extend Stock (Solved)

Post by tenkraD » 13 Apr 2018, 08:22

Hi mohal,

thanks i knew it, the same i allready tried yesterday but i must have made an failure somewhere cause i tried it today again and its working.

Example in post post6012.html#p6012 is updated

Post Reply