Skip to content

Commit

Permalink
Merge pull request #1 from justuno-com/master
Browse files Browse the repository at this point in the history
merging 1.6.3
  • Loading branch information
socks415 authored Mar 5, 2021
2 parents f58d076 + 7bcfcfa commit cb92c62
Show file tree
Hide file tree
Showing 20 changed files with 309 additions and 120 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ cp -r $REPO-$VERSION/* . ;
rm -rf $REPO-$VERSION ;
rm -rf var/cache
```

<h2 id="account-number">Where to find my «Justuno Account Number»?</h2>

![](https://mage2.pro/uploads/default/original/2X/4/429d007f47381d01e5eb2d33d762d77fd2e04932.png)
![](https://mage2.pro/uploads/default/original/2X/3/3ef7cd3ad314c5e2e105f56154385bbe9be0f617.png)
23 changes: 18 additions & 5 deletions app/code/community/Justuno/M1/Catalog.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php
use Justuno_M1_Filter as Filter;
use Justuno_M1_Lib as L;
use Justuno_M1_Response as R;
use Justuno_M1_Settings as S;
use Justuno_M1_Settings as Ss;
use Mage_Catalog_Model_Category as C;
use Mage_Catalog_Model_Product as P;
use Mage_Catalog_Model_Product_Visibility as V;
use Mage_Catalog_Model_Resource_Category_Collection as CC;
use Mage_Catalog_Model_Resource_Product_Collection as PC;
use Mage_Core_Model_Store as S;
use Mage_Review_Model_Review_Summary as RS;
use Mage_Tag_Model_Resource_Tag_Collection as TC;
use Mage_Tag_Model_Tag as T;
Expand All @@ -16,8 +18,19 @@ final class Justuno_M1_Catalog {
* 2019-10-31
* @used-by Justuno_M1_ResponseController::catalogAction()
*/
static function p() {R::p(function() {
static function p() {R::p(function(S $s) {
/**
* 2020-11-27
* 1) "Disable the «Use Flat Catalog Product» option for the `jumagext/response/catalog` request":
* https://github.com/justuno-com/m1/issues/50
* 2) We can not use @see \Mage_Catalog_Helper_Product_Flat::disableFlatCollection()
* because it exists only in Magento ≥ 1.9.4.0:
* https://github.com/OpenMage/magento-mirror/blob/1.9.4.0/app/code/core/Mage/Catalog/Helper/Product/Flat.php#L175-L187
* https://github.com/OpenMage/magento-mirror/blob/1.9.3.0/app/code/core/Mage/Catalog/Helper/Product/Flat.php
*/
Justuno_M1_Rewrite_Catalog_Helper_Product_Flat::$JU_DISABLE = true;
$pc = new PC; /** @var PC $pc */
$pc->addStoreFilter($s); # 2021-01-30 "Make the module multi-store aware": https://github.com/justuno-com/m1/issues/51
$pc->addAttributeToSelect('*');
/**
* 2019-10-30
Expand All @@ -31,7 +44,7 @@ static function p() {R::p(function() {
$pc->addAttributeToFilter('visibility', ['in' => [
V::VISIBILITY_BOTH, V::VISIBILITY_IN_CATALOG, V::VISIBILITY_IN_SEARCH
]]);
$brand = S::brand(); /** @var string $brand */
$brand = Ss::brand(); /** @var string $brand */
return array_values(array_map(function(P $p) use($brand) { /** @var array(string => mixed) $r */
$rs = new RS; /** @var RS $rs */
$rs->load($p->getId());
Expand Down Expand Up @@ -102,7 +115,7 @@ static function p() {R::p(function() {
,'Variants' => Justuno_M1_Catalog_Variants::p($p)
] + Justuno_M1_Catalog_Images::p($p);
if ('configurable' === $p->getTypeId()) {
$ct = $p->getTypeInstance(); /** @var Mage_Catalog_Model_Product_Type_Configurable $ct */
$ct = L::productTI($p); /** @var Mage_Catalog_Model_Product_Type_Configurable $ct */
$opts = array_column($ct->getConfigurableAttributesAsArray($p), 'attribute_code', 'id');
/**
* 2019-10-30
Expand All @@ -121,7 +134,7 @@ static function p() {R::p(function() {
*/
return $r + ['BrandId' => $brand, 'BrandName' => !$brand ? null : ($p->getAttributeText($brand) ?: null)];
}, Filter::p($pc)->getItems()));
}, true);}
});}

/**
* 2019-10-27
Expand Down
15 changes: 7 additions & 8 deletions app/code/community/Justuno/M1/Catalog/Variants.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ static function p(P $p) { /** @var array(array(string => mixed)) $r */
$r = [self::variant($p)];
}
else {
$ct = $p->getTypeInstance(); /** @var Mage_Catalog_Model_Product_Type_Configurable $ct */
# 2019-30-31
# "A configurable product without any associated child products does not produce variants":
# https://github.com/justuno-com/m1/issues/26
$ct = L::productTI($p); /** @var Mage_Catalog_Model_Product_Type_Configurable $ct */
if (!($ch = $ct->getUsedProducts(null, $p))) { /** @var P $ch */
# 2019-30-31
# "Products: some Variants are objects instead of arrays of objects":
# https://github.com/justuno-com/m1/issues/32
$r = [self::variant($p)];
# 2020-11-23
# 1) "A configurable product without any associated child products should not produce variants":
# https://github.com/justuno-com/m2/issues/21
# 2) It should solve «Products of type `configurable` do not have a quantity»
# https://github.com/justuno-com/m2/issues/20
$r = [];
}
else {
$opts = array_column($ct->getConfigurableAttributesAsArray($p), 'attribute_code', 'id');
Expand Down
3 changes: 3 additions & 0 deletions app/code/community/Justuno/M1/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ final class Justuno_M1_DB {
* 2019-11-07
* @used-by select()
* @used-by Justuno_M1_Orders::stat()
* @used-by Justuno_M1_Response::store()
* @used-by app/code/community/Justuno/M1/sql/Justuno_M1/mysql4-install-1.4.3.php
* @return MySQL
*/
Expand All @@ -16,13 +17,15 @@ static function conn() {return self::res()->getConnection('write');}
/**
* 2019-11-07
* @used-by Justuno_M1_Orders::stat()
* @used-by Justuno_M1_Response::store()
* @return Select
*/
static function select() {return self::conn()->select();}

/**
* 2019-11-07
* @used-by Justuno_M1_Orders::stat()
* @used-by Justuno_M1_Response::store()
* @used-by app/code/community/Justuno/M1/sql/Justuno_M1/mysql4-install-1.4.3.php
* @param string $s
* @return string
Expand Down
6 changes: 4 additions & 2 deletions app/code/community/Justuno/M1/Inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
use Mage_Catalog_Model_Product as P;
use Mage_Catalog_Model_Product_Visibility as V;
use Mage_Catalog_Model_Resource_Product_Collection as PC;
use Mage_Core_Model_Store as S;
# 2020-05-06 "Implement an endpoint to return product quantities": https://github.com/justuno-com/m1/issues/45
final class Justuno_M1_Inventory {
/**
* 2020-05-06
* @used-by Justuno_M1_ResponseController::inventoryAction()
*/
static function p() {R::p(function() {
static function p() {R::p(function(S $s) {
$pc = new PC; /** @var PC $pc */
$pc->addStoreFilter($s); # 2021-01-30 "Make the module multi-store aware": https://github.com/justuno-com/m1/issues/51
/**
* 2020-05-06
* 1) «We don't want to include products that have been disabled or have only disabled variants»:
Expand All @@ -22,5 +24,5 @@ static function p() {R::p(function() {
return array_values(array_map(function(P $p) {return [
'ID' => $p->getId(), 'Variants' => Justuno_M1_Inventory_Variants::p($p)
];}, $pc->getItems()));
}, true);}
});}
}
10 changes: 5 additions & 5 deletions app/code/community/Justuno/M1/Inventory/Variants.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
use Justuno_M1_Lib as L;
use Mage_Catalog_Model_Product as P;
use Mage_CatalogInventory_Model_Stock_Item as SI;
// 2020-05-06 "Implement an endpoint to return product quantities": https://github.com/justuno-com/m1/issues/45
# 2020-05-06 "Implement an endpoint to return product quantities": https://github.com/justuno-com/m1/issues/45
final class Justuno_M1_Inventory_Variants {
/**
* 2020-05-06
Expand All @@ -11,13 +12,12 @@ final class Justuno_M1_Inventory_Variants {
*/
static function p(P $p) { /** @var array(array(string => mixed)) $r */
if ('configurable' !== $p->getTypeId()) {
// 2019-30-31
// "Products: some Variants are objects instead of arrays of objects":
// https://github.com/justuno-com/m1/issues/32
# 2019-30-31
# "Products: some Variants are objects instead of arrays of objects": https://github.com/justuno-com/m1/issues/32
$r = [self::variant($p)];
}
else {
$ct = $p->getTypeInstance(); /** @var Mage_Catalog_Model_Product_Type_Configurable $ct */
$ct = L::productTI($p); /** @var Mage_Catalog_Model_Product_Type_Configurable $ct */
/**
* 2020-05-06
* 1) «We would only want records for Products where the product and at least one of its variants are active.
Expand Down
116 changes: 107 additions & 9 deletions app/code/community/Justuno/M1/Lib.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
<?php
use Exception as E;
use Mage_Bundle_Model_Product_Type as ptBundle;
use Mage_Catalog_Model_Product as P;
use Mage_Catalog_Model_Product_Type_Abstract as ptAbstract;
use Mage_Catalog_Model_Product_Type_Configurable as ptConfigurable;
use Mage_Catalog_Model_Product_Type_Grouped as ptGrouped;
use Mage_Catalog_Model_Product_Type_Simple as ptSimple;
use Mage_Catalog_Model_Product_Type_Virtual as ptVirtual;
# 2020-01-15
final class Justuno_M1_Lib {
/**
* 2021-01-29
* @used-by Justuno_M1_Response::store()
* @param array(int|string => mixed) $a
* @param string|string[]|int|null $k
* @param mixed $d
* @return mixed|null|array(string => mixed)
*/
static function a(array $a, $k, $d = null) {return is_null($k) ? $a : (isset($a[$k]) ? $a[$k] : $d);}

/**
* 2020-01-21
* @used-by Justuno_M1_CartController::product()
* @used-by Justuno_M1_Response::store()
* @param mixed $cond
* @param null $m
* @return mixed
Expand All @@ -14,15 +32,15 @@ static function assert($cond, $m = null) {return $cond ?: self::error($m);}

/**
* 2020-03-13
* @used-by \Justuno_M1_Catalog_Variants::variant()
* @used-by Justuno_M1_Catalog_Variants::variant()
* @param boolean $v
* @return string
*/
static function bts($v) {return $v ? 'true' : 'false';}

/**
* 2020-09-29
* @used-by \Justuno_M1_Catalog_Images::p()
* @used-by Justuno_M1_Catalog_Images::p()
* @param string $haystack
* @param string $needle
* @return bool
Expand All @@ -39,6 +57,25 @@ static function contains($haystack, $needle) {return false !== strpos($haystack,
static function ejs($v) {return !is_string($v) ? self::json_encode($v) : implode(
str_replace("'", '\u0027', trim(json_encode($v), '"')), ["'", "'"]
);}

/**
* 2020-01-21
* @used-by assert()
* @used-by Justuno_M1_Response::store()
* @param string|string[]|mixed|E|null ...$m
* @throws E
*/
static function error(...$m) {throw $m instanceof E ? $m : new E(
is_null($m) ? null : (is_array($m) ? implode("\n\n", $m) : sprintf(...$m))
);}

/**
* 2021-01-29
* @used-by \Justuno_M1_Response::store()
* @param array $a
* @return mixed|null
*/
static function first(array $a) {return !$a ? null : reset($a);}

/**
* 2020-01-15
Expand All @@ -64,6 +101,27 @@ static function json_encode($v) {return json_encode($v,
JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE
);}

/**
* 2021-01-27
* 1) In Magento 2, the \Magento\Catalog\Model\Product::getTypeInstance() method does not have arguments:
* https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Catalog/Model/Product.php#L628-L640
* It always returns a singleton:
* 1.1) \Magento\Catalog\Model\Product\Type::factory():
* https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Catalog/Model/Product/Type.php#L114-L135
* 1.2) \Magento\Catalog\Model\Product\Type\Pool::get()
* https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Catalog/Model/Product/Type/Pool.php#L31-L49
* 2) In Magento 1, the method has an optional $singleton argument with the default `false` value:
* @uses \Mage_Catalog_Model_Product::getTypeInstance()
* https://github.com/OpenMage/magento-mirror/blob/1.9.4.5/app/code/core/Mage/Catalog/Model/Product.php#L252-L275
* @used-by Justuno_M1_CartController::addAction()
* @used-by Justuno_M1_Catalog::p()
* @used-by Justuno_M1_Catalog_Variants::p()
* @used-by Justuno_M1_Inventory_Variants::p()
* @param P $p
* @return ptAbstract|ptBundle|ptConfigurable|ptGrouped|ptSimple|ptVirtual
*/
static function productTI(P $p) {return $p->getTypeInstance(true);}

/**
* 2020-01-21
* @used-by reqI()
Expand All @@ -88,12 +146,52 @@ static function req($k, $d = null) {return Mage::app()->getRequest()->getParam($
static function reqI($k, $d = null) {return (int)self::req($k, $d);}

/**
* 2020-01-21
* @used-by assert()
* @param string|string[]|mixed|E|null ...$m
* @throws E
* 2021-01-29
* @used-by Justuno_M1_Response::store()
* @param array(int|string => mixed) $a
* @param \Closure|string|null $f [optional]
* @return array(int|string => mixed)
*/
private static function error(...$m) {throw $m instanceof E ? $m : new E(
is_null($m) ? null : (is_array($m) ? implode("\n\n", $m) : sprintf(...$m))
);}
static function sort(array $a, $f = null) {
$isAssoc = self::is_assoc($a); /** @var bool $isAssoc */
if (!$f) {
$isAssoc ? asort($a) : sort($a);
}
else {
if (!$f instanceof \Closure) {
$m = $f ?: 'getId'; /** @var string $m */ /** @uses Mage_Core_Model_Abstract::getId() */
$f = function($a, $b) use($m) {return !is_object($a) ? $a - $b : $a->$m() - $b->$m();};
}
/** @noinspection PhpUsageOfSilenceOperatorInspection */
$isAssoc ? @uasort($a, $f) : @usort($a, $f);
}
return $a;
}

/**
* 2021-01-29
* @used-by Justuno_M1_Response::store()
* @param int|string $v
* @param array(int|string => mixed) $map
* @return int|string|mixed
*/
static function tr($v, array $map) {return self::a($map, $v, $v);}

/**
* 2021-01-29
* @used-by Justuno_M1_Lib::sort()
* @param array(int|string => mixed) $a
* @return bool
*/
private static function is_assoc(array $a) {
if (!($r = !$a)) { /** @var bool $r */
foreach (array_keys($a) as $k => $v) {
if ($k !== $v) {
$r = true;
break;
}
}
}
return $r;
}
}
Loading

0 comments on commit cb92c62

Please sign in to comment.