Skip to content

Commit

Permalink
fix: get and save data
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreBulete committed Nov 10, 2024
1 parent 2dc7eac commit 5b7a6f7
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Model/Data/Payload/SavePayloadValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class SavePayloadValue implements SavePayloadValueInterface
/**
* @var string
*/
protected string $value;
protected ?string $value = null;

/**
* @var string
*/
protected string $storeViewId;
protected string $storeViewId = '';

/**
* @inheritDoc
Expand Down
4 changes: 2 additions & 2 deletions Model/GetProductAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ protected function getAttributeConfig(string $attributeCode): GetResponseConfigI
function (AttributeOptionInterface $attributeOption) {
/** @var GetResponseConfigOptionsInterface $option */
$option = $this->getResponseConfigOptionsInterfaceFactory->create();
$option->setLabel($attributeOption->getLabel());
$option->setValue($attributeOption->getValue());
$option->setLabel((string) $attributeOption->getLabel());
$option->setValue((string) $attributeOption->getValue());
return $option;
},
$attribute->getOptions()
Expand Down
26 changes: 16 additions & 10 deletions Model/SaveProductAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,22 @@ public function execute(SavePayloadInterface $payload): \Opengento\BetterBo\Api\
{
$success = $error = [];

$dataByStoreId = array_reduce(
$payload->getValues(),
static function ($r, SavePayloadValueInterface $value) use ($payload) {
$r[$value->getStoreViewId()] = [
$payload->getAttributeCode() => $value->getValue()
];
return $r;
},
[]
);
// $dataByStoreId = array_reduce(
// $payload->getValues(),
// static function ($r, SavePayloadValueInterface $value) use ($payload) {
// $r[$value->getStoreViewId()] = [
// $payload->getAttributeCode() => $value->getValue()
// ];
// return $r;
// },
// []
// );
$dataByStoreId = [];
foreach ($payload->getValues() as $value) {
$dataByStoreId[$value->getStoreViewId()] = [
$payload->getAttributeCode() => $value->getValue()
];
}

foreach ($dataByStoreId as $storeId => $data) {
try {
Expand Down
20 changes: 18 additions & 2 deletions Observer/AdminLoginCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,26 @@ public function execute(Observer $observer)
CustomUserContext::USER_TYPE_ADMIN
);
$params = $this->tokenParametersFactory->create();

$token = $this->tokenIssuer->create($context, $params);

// Create token
$this->createAdminCookie($token);

// Add these lines to save token in extra_data
$extraData = $user->getExtra() ?: [];
$this->saveTokenInDB($user, $token);
}

/**
* Save token in extra_data
*
* @param User $user
* @param string $token
*
* @return void
*/
protected function saveTokenInDB(User $user, string $token): void
{
$extraData = json_decode($user->getExtra(), true) ?: [];
$extraData['betterbo_token'] = $token;
$user->setExtra(json_encode($extraData));
$this->userResource->save($user);
Expand All @@ -56,6 +70,8 @@ public function execute(Observer $observer)
/**
* Create admin cookie
*
* @deprecated
*
* @param string $token
*
* @return void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
$extraData = json_decode($user->getExtra(), true) ?: [];
$bearer = $extraData['betterbo_token'];

// dd($bearer);

?>

<div
Expand Down
23 changes: 16 additions & 7 deletions view/adminhtml/web/js/catalog/product/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23454,14 +23454,14 @@ function render(_ctx, _cache, $props, $setup, $data, $options) {
type: "error"
})])) : (0,vue__WEBPACK_IMPORTED_MODULE_0__.createCommentVNode)("v-if", true), ((0,vue__WEBPACK_IMPORTED_MODULE_0__.openBlock)(true), (0,vue__WEBPACK_IMPORTED_MODULE_0__.createElementBlock)(vue__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,vue__WEBPACK_IMPORTED_MODULE_0__.renderList)($setup.productStore.values, function (attribute, index) {
return (0,vue__WEBPACK_IMPORTED_MODULE_0__.openBlock)(), (0,vue__WEBPACK_IMPORTED_MODULE_0__.createElementBlock)("div", {
key: attribute.storeViewId,
key: attribute.store_view_id,
"class": "drawer-row"
}, [(0,vue__WEBPACK_IMPORTED_MODULE_0__.createVNode)(_component_el_form_item, {
label: attribute.storeViewLabel,
label: attribute.store_view_label,
"class": (0,vue__WEBPACK_IMPORTED_MODULE_0__.normalizeClass)({
'test': true,
'error': $setup._findStoreViewId($setup.productStore.errorValues, attribute.storeViewId),
'success': $setup._findStoreViewId($setup.productStore.successValues, attribute.storeViewId)
'error': $setup._findStoreViewId($setup.productStore.errorValues, attribute.store_view_id),
'success': $setup._findStoreViewId($setup.productStore.successValues, attribute.store_view_id)
})
}, {
"default": (0,vue__WEBPACK_IMPORTED_MODULE_0__.withCtx)(function () {
Expand Down Expand Up @@ -23512,7 +23512,7 @@ function render(_ctx, _cache, $props, $setup, $data, $options) {
return [(0,vue__WEBPACK_IMPORTED_MODULE_0__.createElementVNode)("span", {
"class": "trash-icon",
onClick: function onClick($event) {
return $setup._delete($setup.attributeCode, attribute.storeViewId);
return $setup._delete($setup.attributeCode, attribute.store_view_id);
}
}, [(0,vue__WEBPACK_IMPORTED_MODULE_0__.createVNode)(_component_unicon, {
name: "trash-alt",
Expand Down Expand Up @@ -23609,12 +23609,12 @@ var useProduct = (0,pinia__WEBPACK_IMPORTED_MODULE_1__.defineStore)('product', {
return state.values.filter(function (currentValue) {
console.log(currentValue);
var originalValue = state.originalValues.find(function (original) {
return original.storeViewId === currentValue.storeViewId;
return original.store_view_id === currentValue.store_view_id;
});
return (originalValue === null || originalValue === void 0 ? void 0 : originalValue.value) !== currentValue.value;
}).map(function (value) {
return {
storeViewId: value.storeViewId,
store_view_id: value.store_view_id,
value: value.value
};
});
Expand Down Expand Up @@ -23653,6 +23653,9 @@ var useProduct = (0,pinia__WEBPACK_IMPORTED_MODULE_1__.defineStore)('product', {
_this.originalValues = JSON.parse(JSON.stringify(data.data.values));
_this.config = data.data.config;
_this.loading = false;
})["catch"](function (error) {
(0,_vue_utils_api__WEBPACK_IMPORTED_MODULE_0__._catch)(error);
_this.loading = false;
}));
case 4:
case "end":
Expand Down Expand Up @@ -23707,6 +23710,9 @@ var useProduct = (0,pinia__WEBPACK_IMPORTED_MODULE_1__.defineStore)('product', {
message: "Values not saved for ".concat(_this2.errorValues.length, " stores")
});
}
})["catch"](function (error) {
(0,_vue_utils_api__WEBPACK_IMPORTED_MODULE_0__._catch)(error);
_this2.loading = false;
});
},
/**
Expand All @@ -23733,6 +23739,9 @@ var useProduct = (0,pinia__WEBPACK_IMPORTED_MODULE_1__.defineStore)('product', {
}).then(function (response) {
var data = response.data;
_this3.errorLoading = false;
})["catch"](function (error) {
(0,_vue_utils_api__WEBPACK_IMPORTED_MODULE_0__._catch)(error);
_this3.errorLoading = false;
});
}
}
Expand Down
10 changes: 5 additions & 5 deletions vue/adminhtml/catalog/product/Attributes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
</div>

<div
v-for="(attribute, index) in productStore.values" :key="attribute.storeViewId"
v-for="(attribute, index) in productStore.values" :key="attribute.store_view_id"
class="drawer-row"
>
<el-form-item
:label="attribute.storeViewLabel"
:label="attribute.store_view_label"
:class="{
'test': true,
'error': _findStoreViewId(productStore.errorValues, attribute.storeViewId),
'success': _findStoreViewId(productStore.successValues, attribute.storeViewId),
'error': _findStoreViewId(productStore.errorValues, attribute.store_view_id),
'success': _findStoreViewId(productStore.successValues, attribute.store_view_id),
}"
>
<el-input
Expand Down Expand Up @@ -75,7 +75,7 @@
<template #reference>
<span
class="trash-icon"
@click="_delete(attributeCode, attribute.storeViewId)"
@click="_delete(attributeCode, attribute.store_view_id)"
>
<unicon
name="trash-alt"
Expand Down
15 changes: 12 additions & 3 deletions vue/adminhtml/stores/product.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineStore } from "pinia";
import axios from 'axios'
import { _axios, _message } from '@/vue/utils/api'
import { _axios, _message, _catch } from '@/vue/utils/api'

/**
* Category store
Expand Down Expand Up @@ -30,10 +30,10 @@ export const useProduct = defineStore('product', {
_differentValues(state: any) {
return state.values.filter((currentValue: any) => {
console.log(currentValue)
const originalValue = state.originalValues.find((original: any) => original.storeViewId === currentValue.storeViewId);
const originalValue = state.originalValues.find((original: any) => original.store_view_id === currentValue.store_view_id);
return originalValue?.value !== currentValue.value;
}).map((value: any) => ({
storeViewId: value.storeViewId,
store_view_id: value.store_view_id,
value: value.value
}))
}
Expand Down Expand Up @@ -67,6 +67,9 @@ export const useProduct = defineStore('product', {
this.originalValues = JSON.parse(JSON.stringify(data.data.values))
this.config = data.data.config
this.loading = false
}).catch((error: any) => {
_catch(error)
this.loading = false
})
},
/**
Expand Down Expand Up @@ -118,6 +121,9 @@ export const useProduct = defineStore('product', {
message: `Values not saved for ${this.errorValues.length} stores`
})
}
}).catch((error: any) => {
_catch(error)
this.loading = false
})
},
/**
Expand All @@ -144,6 +150,9 @@ export const useProduct = defineStore('product', {
}).then((response: any) => {
const data = response.data
this.errorLoading = false
}).catch((error: any) => {
_catch(error)
this.errorLoading = false
})
}
}
Expand Down

0 comments on commit 5b7a6f7

Please sign in to comment.