vbpupil / product
Product Library
Requires
- php: >=7.2
- myclabs/php-enum: ^1.7
- vbpupil/collection: ^1.0
Requires (Dev)
- phpunit/phpunit: 7.0.0
- symfony/var-dumper: ^4.3
- dev-master
- 5.0.0
- v4.1.x-dev
- 4.1.2
- 4.1.1
- 4.1.0
- 4.0.0
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.0.0
- 1.3.0
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.1.1
- 1.1.0
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-seo
- dev-dev_adding_mpn_ean_and_barcode
- dev-tweak_to_product_code
- dev-experimental
- dev-product_type_and_variant_type_swappover_test
- dev-UML
This package is auto-updated.
Last update: 2024-10-22 19:57:06 UTC
README
ProductLibrary
A Product Object can have many components based on how complicated your requirements are. Below outlines the general configurations:
SimpleProduct - Without Prices
A SimpleProduct does NOT have any prices. Below shows how a SimpleProduct can be initiated:
$prod = new SimpleProduct( 'Iphone X', new Collection() ); $prod->setLive(true); $prod->setSlug('iphone-x'); //defines urls safe string $prod->setDescription( '<p>The iPhone X, pronounced "iPhone 10," was introduced at Apple\'s September 2017 event as a classic "One more thing...".</p>', 'long_description');
Get Description
echo $prod->getItem('long_description');
Get Descriptions
foreach ($prod->getItems() as $desc) { echo $desc; }
Get Product Attributes
- getBrandName() - brand name associated with product
- getBrandId() - brand id associated with product
GeneralProduct
On the face of it a General Product is the same as a Simple Product except it has a concept of Variations which itself offers some interesting additions.
To add Variations simplly start by passing in an empty Collection:
$prod->setVariations( new Collection() );
Once you have created the Collection simply use it as you would any other Collection object (the above descriptions functionality in Simple Product uses the same functionality).
To add a Variation:
$myVariation = new \vbpupil\Variation\AbstractVariation( [ 'title' => 'FFF', 'product_code' => 'MYPRODCODE-01' ] ); $prod->variations->addItem($v);
Get Variant Attributes
- getBarcode() - barcode of a variant
- getEan() - ean of a variant
- getMpn() - mpn of a variant
- getPriceType() - price type of a variant ie single or pivot
- getUnitOfSale() - unit of sale of a varient ie bag, pallet, jumbo bag etc
- getMinDelQty() - how much qty to purchase before del is available
- getMaxDelQty() - how much qty is too much before only colection is available
Pricing
SinglePrice
This handles most use cases when a product variation may have a few prices attributed to it such as prices, special prices, cost prices etc but will only be sold for a single prices. When asking the object for its getPrice() method you will be returned a single prices. Note the object will run a check to see if the Special prices is set/valid and return that if true, if not the sell prices will be returned.
PivotPrice
This object will handle the pivot prices style structure, ie:
to identify which price type a variant is (ie single or pivot) you can use getVariantPriceTypes()
to identify which is the cheapest variant id you can use getCheapestVariantiD()
to identify which is the cheapest variant price you can use getCheapestVariantPrice()
Stock
Stock can be measured depending upon needs, the following are available.
SimpleStock
Simple stock offers a simple holding of a stock figure and passes back whenever called upon.
AuditableStock
Auditable stock has the ability to verify what the current stock figure has on hand by performing a retrospective check of its inventory history and spitting out its findings.
Auditable
The auditable class is on hand to offer an explanation of why an items stock figure has changed - ie BOOK_IN/BOOK_OUT etc etc.
AuditableType
This class simply defines what can be accepted as a valid reason. For instance when newing up an Auditable:
$a = new Auditable( 2, AuditableType::SALE(), 'Sold', '2019-08-22 14:42:20', AuditableAssociatedDocumentType::SALES_ORDER(), 115 )
A AuditableType::SALE() is passed into to represent a SALE item. This class is governed by Enums which outlines what type is available.
AuditableAssociatesDocumentType
This class allows you to specify what supporting document accompanies the stock change, for instance a SALES_ORDER (with accompanying SALES ORDER ID) would support a sale which resulted in the stock being reduced by 1. Below shows this code in action.
$a = new Auditable( 2, AuditableType::SALE(), 'Sold', '2019-08-22 14:42:20', AuditableAssociatedDocumentType::SALES_ORDER(), 115 )
An AuditableAssociatedDocumentType::SALES_ORDER() is passed in to represent a SALES_ORDER. This class is governed by Enums which outlines what supporting document types are available.