Cómo encajo el sistema de gestión de productos de Presta Shop en cinco botones

¡Atención!

Después de leer el artículo, puede que tengas la impresión de que amo el BDSM o algo así, pero solo te lo parece a ti.





Problemas con la tienda

Trabajo en una tienda de bicicletas habitual en el centro de Varsovia. Negociamos tanto en papelería como en Internet. Número medio de bicicletas compradas por día ~ 2 durante todo el año. Al mismo tiempo, el pico de ventas cae en el verano, y luego podemos tener ~ 17 pedidos en línea por día y el mismo número en la tienda, y en invierno no podemos vender nada en absoluto.





En 2020. En relación con la pandemia de COVID, la demanda de bicicletas ha crecido a un ritmo increíble y nosotros, como oficina decente, hemos comenzado a expandirnos.





Esto llevó al hecho de que al final de la temporada pasada, los pedidos de bicicletas solo inexistentes aumentaron en promedio hasta 4 veces por semana durante los 4 meses más productivos. Y esto es ~ 16 inconsistencias en el sitio por mes (sin contar las fallas en la tienda).





Pedidos cancelados
Pedidos cancelados

Este año, con la aparición de otro gran almacén, la situación ha empeorado y ahora, además de las bicicletas inexistentes, se añadieron las que no estaban y muchas veces era imposible llevarlas a los clientes a tiempo.





, - EXEL, , . , . 2 2-3 .





. , , , – , . .





, , - . . , . :





, .





:





  1. Python API PrestaShop;





  2. , -, . ;





  3. Chrome . , Chrome.





middle-, . .





API PrestaShop

API PrestaShop Python , , PS 5% ( 1.6 ). — prestapyt, . , , .





, , API, PS. , , .





, , ! , .





Git





- , .





, , .





:





  1. reference ;





  2. — ;





  3. , , stock_availables. ;





  4. associations .





  5. , , > 0 — . – , .





  6. XML stock_availables, .





.





, - , .





API

https://domain.com/api. , . id – , «products» . , .





API XML, :





<prestashop>
	<api shopName="myshop">
		<addresses xlink:href="https://domain.com/api/addresses" get="true" put="false" post="false" delete="false" head="false"></addresses>
	</api>
</prestashop>
      
      



- . https://domain.com/api/products:





<prestashop>
  <products>
    <product id="22" xlink:href="https://domain.com/api/products/22"/>
    <product id="24" xlink:href="https://domain.com/api/products/24"/>
    <product id="265" xlink:href="https://domain.com/api/products/265"/>
    <product id="294" xlink:href="https://domain.com/api/products/294"/>
  <products />
<prestashop />
      
      



.





requests. , Requests — , .





API PS Basic ( ). . requests:





request_url = «https://domain.com/api»
get_combination_xml = requests.get(request_url, auth=(self.api_secret_key, ''))
      
      



  200, , XML. .





XML

– xml.etree. , , ( ), , Python.





:





#     2 
from xml.etree import ElementTree as ET
from xml.etree.ElementTree import ElementTree
#  xml.etree


def xml_data_extractor(data, tag):
# data – XML 
# tag = products–     
try:
	xml_content = ET.fromstring(data.content) #   ElementTree.     .     .
	general_tag = xml_content[0] #    –   
	tag = general_tag.find(tag) #   
	tag_inner_link = tag.get('{http://www.w3.org/1999/xlink}href') #    
	#      href         

  #      
	product_meta = {'product_link': tag_inner_link}
	
  return product_meta

except:
	return None
      
      



 : https://domain.com/api/products. , .





None except Try. , , , , .





PS

PS . , – SQL . XML , — , .





:





https://domain.com/api/combinations/?filter[reference]=reference



, reference — .





- -, : KRHE1Z26X14M200034.





  , . ! Git:





«»

( , ). base64 , , , :





def __init__(self, api_secret_key, request_url=None, **kwargs):
	try:
		self.api_secret_key = str(api_secret_key) #!API key is necessary!
		self.api_secret_key_64 = base64.b64encode((self.api_secret_key + ':').encode())
    
except:
	raise TypeError('The secret_key must be a string!')

  
# Main path to working directory
self.base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
self.request_url = request_url
self.kwargs = kwargs.items()

#product meta to return
self.name = None
self.total_quantity = None
self.w_from = None
self.w_to = None
self.date = str(datetime.datetime.now().strftime("%d-%m-%Y, %H:%M"))
      
      



: _xml_data_extractor(), _wd() _logging(), . -.





— . 11. . , , .





middle-

c Python. , - . WSGI- , !





, , .





, . , Django, — middle-, .





, , - .





Solicitud no válida

! https://palachintosh.com/xxx/xxx/



? ( ) , , . .





/?code=1122334455&token=IUFJ44KPQE342M3M109DNWI



( ):





Ejemplo de una solicitud exitosa

success – , , , , - . .





, , , , . Django Django REST. Java Retrofit, .





– – . – - :





token = None

with open(‘token.txt’) as file_t:
	token = file_t[0]

if token == str(request.GET.get(‘token’)):
	// 

return JsonResponse({‘Error’: ‘Invalid token’})
      
      



, , .





Chrome

, , ..





, . . XMLHttpRequest.





CORS. , Access-Control-Allow-Origin. , OPTIONS.





views.py def options(self, request). GET .





100 , .





- , . . :





Proceso de emisión de la tarjeta de garantía

, . «Kod roweru» , .





– PrestaRequest . , .





«sku» , ajax . , ajax . .





var interval;

function main_interval({
    clearInterval(interval);
    
  interval = setInterval(function ({
        href = window.location.href
        if (href.indexOf('https://24.kross.pl/warranty/new') >= 0 ||
            href.indexOf('id_product=') >= 0) {

            if (href.indexOf('id_product=') >= 0) {
                prestaCheck();
                clearInterval(interval);
            }

            if (href.indexOf('https://24.kross.pl/warranty/new') >= 0) {
                location.reload();
                get_buttons();
            }
        }

        if (href.indexOf('https://24.kross.pl/bike-overview/new') >= 0) {
            clearInterval(interval);
            check_all();
        }
    }, 1000);
}
      
      



:





// onclick or enter events
 function getFormData() {
    var getForm = document.forms[0];

    if (getForm != null) {
        if (getForm.hasChildNodes("sku") && getForm.sku != null){
            var code = String(getForm.sku.value);
        }

        if (getForm.hasChildNodes("bike_model") && getForm.bike_model != null) {
            edit_msg = document.querySelector(".message-container > span > h1");
            edit_msg.innerText = "Rower " + String(getForm.bike_model.value) + " zostanie usunięty ze stanów!";
        }

        if (code != null && getForm.serial_number != null) {
            sendRequest(code);
        }
    }
}
      
      



bike_model , , . :





var getBodyBlock = document.querySelector('body');
var alert_div = document.createElement('div');

alert_div.innerHTML = '<div class="alert-message"><div class="message-container">\
<span><h1></h1></span>\
<div class="inner-buttons">\
<button id="btnYes" class="ant-btn ant-btn-danger">Potwierdzam!</button>\
<button id="btnReserve" class="ant-btn ant-btn-danger">Zdjąć rezerwację</button>\
<button id="btnNo" class="ant-btn ant-btn-success">Nie teraz</button>\
</div></div></div>';

loader = document.createElement('div');
getBodyBlock.appendChild(alert_div);
      
      



: https://github.com/palachintosh/shop_extension





– Android-

, , . . , , , 50 ., .





. , . , .





( )

3 . , :





  • , .





  • , , , - , .





, . - . , - . Java .





Retrofit 2. , Python. , , , , , .





Main Activity 3 – onCreate, scanCode, enterCode , :





protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Spinner fromSpinner = (Spinner) findViewById(R.id.fromSpinner);
    Spinner toSpinner = (Spinner) findViewById(R.id.toSpinner);

    ArrayAdapter<String> adapter = new ArrayAdapter<String> (
            this, android.R.layout.simple_spinner_item, warehouses);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    fromSpinner.setAdapter(adapter);
    toSpinner.setAdapter(adapter);
}

public void scanCode(View view) {
    Intent intent = new Intent(MainActivity.this, Scan.class);
    Spinner get_w_from = (Spinner) findViewById(R.id.fromSpinner);
    Spinner get_w_to = (Spinner) findViewById(R.id.toSpinner);
    EditText editText = (EditText) findViewById(R.id.prodctQuantity);
    String quantity_tt = editText.getText().toString();

    RequestData requestData = new RequestData(
            get_w_from.getSelectedItem().toString(),
            get_w_to.getSelectedItem().toString(),
            quantity_tt);
    intent.putExtra(RequestData.class.getSimpleName(), requestData);
    startActivity(intent);
}
      
      



“Enter Code” . , . – .





Envío de código manual

Scan Code Activity co , Barcode Scanner Google.





Ventana de escaneo de código

Send Code – . , . Retrofit . , , – Java Android , .





github: https://github.com/palachintosh/product_control.git





:





  • – ;





  • – , , ;





  • - , .





:





  • – - , ;





  • – ;





  • – .





  , 2- -.





, , 5:





  1. .





  2. ( , PrestaShop).





  3. "Enter code" .





  4. "Scan code".





  5. – "Send Code".





, , , .





, , , . - - .





: , , , .





, , , .





Las personas que han mirado los repositorios o que en general han leído esto agradecerán los comentarios constructivos y las críticas.





 








All Articles